Query Quandary

FoeHunter

Board Regular
Joined
Nov 12, 2008
Messages
236
I have a query that uses a criteria similar to the one below. The only downside to this is that I have to have the “SearchForm” open in the background while the rest of the code that opens/closes the query then opens the form runs.

Would it be possible to have the search criteria be saved as a global variable or is an all-too-common example where I have made things more difficult than need be by choosing the more troublesome path?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Code:
[FONT=Times New Roman]Like "*" & [forms]![SearchForm].[QNSN1] & "*"[/FONT]
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Is it possible? Yes. It wouldn't need to be "global" it could be a private variable. Either way you would have to have code that populates that variable. You would then have to have a function that returns that variable for your query to work--queries can't reference the global (or private whichever) variable directly.

I have done something similar when I have multiple complicated search forms that use similar queries. I call the function from the query which then looks to see which form is open rather than a specific form as I don't know which form would be open until runtime.

hth,

Rich
 
Upvote 0
That does help. I'll play around with it and google to see if I can figure something out.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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