Setting criteria in visual basic

S

Steve Moody

Does anyone know how to set the criteria for a query using visual basic
code? Thanks!

Steve
 
E

ET Sherman

Can you explain what you are going to do with the query.

Select Query, Report Recordsource etc.

ET Sherman
 
S

Steve Moody

I am using two forms. There will be times when the user will be looking at a
record on form1 and will want to switch to form2, so I've provided a button
to close the form1 and open form2. However, when the switch occurs, I want
form2 to open up with the same record that the user was working on in form1.
To accomplish this, I thought it would be easy if I could open a query, set
the criteria for the ID field to the open record in form1, and then set that
query as the source for form2. That way when form2 opens, it will use the
query as it's source and the query will only contain the one record with the
same ID number. Does that make sense?

I can get form2 to open and I can set it's RecordSource to use a query. I
just can't figure out how to set the query to use the ID number as it's
criteria.

Thanks!

Steve
 
E

ET Sherman

OK, then I would do the following in the On Click event of
your Command Button that you created to close Form1. Make
sure you add this code before your code to close form1.

DoCmd.OpenForm "Form2",acNormal,,"[YourIDField]=
ME.YourIDField"

Basically you will be using the WHERE clause of the
OpenForm action.

Hope this helped.

ET Sherman
 
E

ET Sherman

Note: For the WHERE clause below show it like this:
"[YourIDField]= " & ME.[YourIDField]

ET Sherman

-----Original Message-----
OK, then I would do the following in the On Click event of
your Command Button that you created to close Form1. Make
sure you add this code before your code to close form1.

DoCmd.OpenForm "Form2",acNormal,,"[YourIDField]=
ME.YourIDField"

Basically you will be using the WHERE clause of the
OpenForm action.

Hope this helped.

ET Sherman


-----Original Message-----
I am using two forms. There will be times when the user will be looking at a
record on form1 and will want to switch to form2, so
I've
provided a button
to close the form1 and open form2. However, when the switch occurs, I want
form2 to open up with the same record that the user was working on in form1.
To accomplish this, I thought it would be easy if I
could
open a query, set
the criteria for the ID field to the open record in form1, and then set that
query as the source for form2. That way when form2
opens,
it will use the
query as it's source and the query will only contain the one record with the
same ID number. Does that make sense?

I can get form2 to open and I can set it's RecordSource to use a query. I
just can't figure out how to set the query to use the ID number as it's
criteria.

Thanks!

Steve




.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top