Run Query Name from matching text box value

ccondran08

Registered User.
Local time
Tomorrow, 06:50
Joined
Feb 27, 2014
Messages
58
Just wondering if this can be done, the below code doesn't work. I want to be able to change the order in which certain queries are run by placing the query names in a text box on the main menu so it can the user can modify the names of the queries dynamically. The example below has 2 text boxes on the main menu with the names of the queries in the text box.

Dim Query1 As String
Dim Query2 As String

Query1 = [Forms]![frm_Main_Menu].[txt_First_Query]
Query2 = [Forms]![frm_Main_Menu].[txt_Second_Query]

DoCmd.SetWarnings False

DoCmd.OpenQuery "Query1", acViewNormal, acAdd
Forms!frm_Main_Menu.Refresh
DoCmd.OpenQuery "Query2", acViewNormal, acAdd
Forms!frm_Main_Menu.Refresh

The attached image shows what I'm trying to do.
 

Attachments

  • delete query.png
    delete query.png
    27.2 KB · Views: 161
Last edited:
Remove the double quotes. Otherwise you are referring to the literal string rather than the variable.

DoCmd.OpenQuery Query1, acViewNormal, acAdd

BTW. It really is worth getting the query into a form because it gives you a lot more control over how it presents and behaves.
 
Last edited:
Thanks for taking the time to look at this Galaxiom, however it is still not working. I'm getting the same error message as before. I have attached a copy of the file.
 

Attachments

Two problems.

The Project is called "Database" which is a reserved word. Show the Properties windows in the VBA Editor (Press F4). Highlight the project and then edit the name in the Properties.

Secondly, the form is corrupt.

Select all the objects on it in design view, then copy and paste into a new form. Then copy and paste the code into the new form's module.

After that I would also import everything into a new database.
 
Brilliant, thanks Galaxiom, works perfect. Thanks for you help.
 

Users who are viewing this thread

Back
Top Bottom