MS Access 2003: Use a public string as part of the criteria in a query
This MSAccess tutorial explains how to use a public string variable as part of a criteria in a query in Access 2003 (with screenshots and step-by-step instructions).
Question: In Microsoft Access 2003/XP/2000/97, is it possible to use a public string as part of the criteria in a query?
Answer: Yes, you can use a public string in a query, as long as you follow a few guidelines.
First, the string should be declared globally in a module. To do this, select the Modules tab and click on the New button.
Access should take you to the Microsoft Visual Basic editor. Next, declare your string variable. In this example, we've declared a global string variable called GString.
Now that you've created your string variable, you need to create a function that will return the value of this string. This function is what you will use in your query's criteria.
In this example, we've created a function called GetGString that returns that value of the GString variable.
Now, it's time to use your function in a query.
In this example, we'll return all records from the Suppliers table where the CompanyName matches the value of our string variable.
Advertisements