setting variables to use in macros

G

Guest

I have a macro that runs 3 different queries, this is to delete certain
records in 3 different tables, the id number is the same in each table. The
first query asks for the id number and deletes the records, the second query
asks for the id number and deletes the records in the next table. I am at a
loss to find a way to have the macro ask for the id number one time and save
it to delete the records in all three of the queries, or perhaps the whole
thing could be run with linked queries?
 
A

Allen Browne

Unless you are using Access 2007, macros cannot use variables.

You can do this if you build the SQL statement in code. Here's an example of
how to use the Execute method in code:
http://allenbrowne.com/ser-60.html

You just concatenate the value of the variable into the SQL string, instead
of using a saved query.
 
B

Bob Quintal

=?Utf-8?B?U2FjdG9iZWFy?= <[email protected]>
wrote in
I have a macro that runs 3 different queries, this is to
delete certain records in 3 different tables, the id number is
the same in each table. The first query asks for the id
number and deletes the records, the second query asks for the
id number and deletes the records in the next table. I am at
a loss to find a way to have the macro ask for the id number
one time and save it to delete the records in all three of the
queries, or perhaps the whole thing could be run with linked
queries?

Build an unbound form to run the queries, either through a macro
or in code.Put a textbox on the form to enter the ID number.
Change the Parameter in each query to refer to the name of the
control

Forms!myform!mycontrol with myform,mycontrol being whatever
names you use.

The three queries will use the data in the textbox instead of
asking for it.
 

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