Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Dynamic Query in Access db


Message #1 by "James Bennett" <jbennett@c...> on Tue, 29 Oct 2002 22:39:20
Does anyone know how I can create a query based on a form?  I have a form 
with combo boxes that select from a table, I want to be able to use the 
selections to form the criteria for a query.  I am having one heck of a 
time trying to get the output of the form to enter the data into the 
criteria field of the query...

Any ideas would help much!

Thanks
Jim
Message #2 by "Wesley Kendrick" <wez.k@n...> on Tue, 29 Oct 2002 22:36:28 -0000
Hi Jim

You should enter the full path of the combo boxes

Forms!YourFormName!YourComboBox

into the criteria row of the query

Hope this helps, regards, Wesley Kendrick

----- Original Message -----
From: "James Bennett" <jbennett@c...>
To: "Access" <access@p...>
Sent: Tuesday, October 29, 2002 10:39 PM
Subject: [access] Dynamic Query in Access db


> Does anyone know how I can create a query based on a form?  I have a form
> with combo boxes that select from a table, I want to be able to use the
> selections to form the criteria for a query.  I am having one heck of a
> time trying to get the output of the form to enter the data into the
> criteria field of the query...
>
> Any ideas would help much!
>
> Thanks
> Jim

Message #3 by "James Bennett" <jbennett@c...> on Wed, 30 Oct 2002 13:57:59
Yes, I tried that, the syntax is correct, but the Forms!YourFormName!
YourComboBox apparently doesn't return text.  I put that in the criteria 
field and it treats the criteria as something other than text.  When i 
view the SQL it has: Form... = Forms!Your...  I can't understand why they 
don't equate the way I would think they would.  

Jim

> Hi Jim

You should enter the full path of the combo boxes

Forms!YourFormName!YourComboBox

into the criteria row of the query

Hope this helps, regards, Wesley Kendrick

----- Original Message -----
From: "James Bennett" <jbennett@c...>
To: "Access" <access@p...>
Sent: Tuesday, October 29, 2002 10:39 PM
Subject: [access] Dynamic Query in Access db


> Does anyone know how I can create a query based on a form?  I have a form
> with combo boxes that select from a table, I want to be able to use the
> selections to form the criteria for a query.  I am having one heck of a
> time trying to get the output of the form to enter the data into the
> criteria field of the query...
>
> Any ideas would help much!
>
> Thanks
> Jim

Message #4 by "Bob Bedell" <bobbedell15@m...> on Wed, 30 Oct 2002 14:49:27 +0000
Hi James,

When I'm using a combo box to store values in a table, my combo row
source usually consists of two columns. The first is a numeric value
which I bind to and store in the table, and which does not display in
the combo; the second is a text field that displays in the combo.

Both of the columns that populate the combo are often drawn from a
lookup table that has a 1:M relationship to the table the combo is
storing values in. The bound column is numeric because it is an
autonumber field in the lookup table.

Anyway, the full reference for my combo box's values would be:

Forms!YourFormName!YourComboBox.Column(0)
Forms!YourFormName!YourComboBox.Column(1)

Column(0) is my numeric, bound value; Column(1) is my text value. Try
experimenting with each of these column references in you query
criteria. Maybe you're trying to bind a numeric value (Column(0)) to a
text column in your table. Try refencing Column(1) in your criteria.

I hope some of that makes sense.

Best,

Bob

>From: "James Bennett" <jbennett@c...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: Dynamic Query in Access db
>Date: Wed, 30 Oct 2002 13:57:59
>
>Yes, I tried that, the syntax is correct, but the Forms!YourFormName!
>YourComboBox apparently doesn't return text.  I put that in the criteria
>field and it treats the criteria as something other than text.  When i
>view the SQL it has: Form... = Forms!Your...  I can't understand why they
>don't equate the way I would think they would.
>
>Jim
>
> > Hi Jim
>
>You should enter the full path of the combo boxes
>
>Forms!YourFormName!YourComboBox
>
>into the criteria row of the query
>
>Hope this helps, regards, Wesley Kendrick
>
>----- Original Message -----
>From: "James Bennett" <jbennett@c...>
>To: "Access" <access@p...>
>Sent: Tuesday, October 29, 2002 10:39 PM
>Subject: [access] Dynamic Query in Access db
>
>
> > Does anyone know how I can create a query based on a form?  I have a 
>form
> > with combo boxes that select from a table, I want to be able to use the
> > selections to form the criteria for a query.  I am having one heck of a
> > time trying to get the output of the form to enter the data into the
> > criteria field of the query...
> >
> > Any ideas would help much!
> >
> > Thanks
> > Jim
>


_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

Message #5 by "Dave Loukola" <dave.loukola@H...> on Wed, 30 Oct 2002 16:03:46
Sure James,

dim strSql as string

strSql = "SELECT [field1],[field2] FROM [table] where [field1] = '" & 
cmbYourComboBox & "' AND [field2] = '" & cmbYourComboBox2 & "';"

that should do you.  Don't foget to use the single quotes in the double 
quotes around the combo box names otherwise it won't work.

Dave

> Does anyone know how I can create a query based on a form?  I have a 
form 
w> ith combo boxes that select from a table, I want to be able to use the 
s> elections to form the criteria for a query.  I am having one heck of a 
t> ime trying to get the output of the form to enter the data into the 
c> riteria field of the query...

> Any ideas would help much!

> Thanks
J> im

  Return to Index