Module Help needed for access.

davin2929

Board Regular
Joined
Oct 13, 2002
Messages
129
I need to run a bunch of macros in access that in turn run queries. Unfortunately I have to enter the week number of the year for the queries. So I have to type the week number about 30 times while the macros are running. Is there a way to input the week number once and have all the macros refer to that week number. I think this would have to be done in a module but I'm not sure how to get the macros/queries to refer to the stored number. Any help would be greatly appreciated. Thanks.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What I would suggest:

Create a Form to enter the data: Have a textbox for the data and a command button(more on this later)

In all your queries, everywhere you have the date criteria, you want to reference your form textbox..ie [Forms]![FormName]![TexboxName]

the command button on the form will run your macro, which will run your queries.
You could shorten this by writing code in the command button that will run the queries(we can cover this if you would like).

To run your queries,
1) Open the form
2) enter the date
3) click the command button to trigger the macro to trigger the query.

All queries run and you only have to enter the date once!

HTH,
CT
 
Upvote 0
Ok, not picking at wording specifically but I think what you meant to say is you execute a macro and while the 30 QUERIES are running you have to type in variable values each time.

Have you thought about rewriting all this as VBA instead?
Gives you a lot more flexibility on things including just defining a variable as your date once and then having the value dynamically added to the queries within the code.

Code:
strVal = InputBox("Which week would you like?", "Week Chooser")

strSQL = "DELETE * FROM tblName WHERE fld1='" & strVal & "'"
DoCmd.RunSQL strSQL

This would perform an action query (deletion) on each record where the week happened to be the one you chose. I, um, would choose a different action query to test with, though.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,590
Messages
6,160,668
Members
451,662
Latest member
reelspike

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top