set critera in a query using a macro

R

Ric

I need to set the critera in a number of queries using a macro. I have 12
macros, one for each month. They set the critery in the month column of
different queries. I had used the sendkey command but it will not work in
Access 2003. I upgraded from an old version that worked fine with sendkeys.
 
O

Ofer Cohen

Don't use macro's, they are quite limited, and you can't control there
errors
Instead of using 12 macro's, and I don't know how many queries, create a
form where the user can input the month and then press a button to activate
the query.
In the query create a reference to this text box in the form

Select * From TableName Where MonthFieldName =
Forms![FormName]![TextBoxName]

That way, you have one query with a form where the user select a month, to
open the query use

Docmd.OpenQuery "QueryName"

-----
Good Luck
BS"D

Ric said:
I need to set the critera in a number of queries using a macro. I have 12
macros, one for each month. They set the critery in the month column of
different queries. I had used the sendkey command but it will not work in
Access 2003. I upgraded from an old version that worked fine with
sendkeys.
 
J

John W. Vinson

I need to set the critera in a number of queries using a macro. I have 12
macros, one for each month. They set the critery in the month column of
different queries. I had used the sendkey command but it will not work in
Access 2003. I upgraded from an old version that worked fine with sendkeys.

Would you settle for *one* query with no macro and no code, to do the same
thing?

You can use a single Parameter query with a criterion

[Enter month:]

to prompt the user to enter a month. You don't describe your queries or
tables, so I'm not sure what the exact criterion would be - but you're doing
this the hard way, needlessly!

John W. Vinson [MVP]
 
R

Ric

Thank you but, I had the old database using sendkey to arrow down the the
critera field in about 15 different queries to set the month. Then I am
pulling data into a number of forms based on the queries set. I am then
calculating totals from a number of forms. When I converted to 2003 the
macros error out. Send key does not want to work. I get a message that I
need to load the add ins. I have and sendkey still does not work. A MAJOR
rebuild would be needed and I would prefer not to.

Ofer Cohen said:
Don't use macro's, they are quite limited, and you can't control there
errors
Instead of using 12 macro's, and I don't know how many queries, create a
form where the user can input the month and then press a button to activate
the query.
In the query create a reference to this text box in the form

Select * From TableName Where MonthFieldName =
Forms![FormName]![TextBoxName]

That way, you have one query with a form where the user select a month, to
open the query use

Docmd.OpenQuery "QueryName"

-----
Good Luck
BS"D

Ric said:
I need to set the critera in a number of queries using a macro. I have 12
macros, one for each month. They set the critery in the month column of
different queries. I had used the sendkey command but it will not work in
Access 2003. I upgraded from an old version that worked fine with
sendkeys.
 

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