Note: Please bear with me as I'm relatively new to Access... everything I have learned has been through searching Google as necessary.
So I am creating a form with the sole purpose of searching through a database. In one use-case, the user has the option to select multiple options to filter a search by, for privacy reasons we can say "Blue, Green, Red, Brown". The user can select any combination of those colors, including all or none. In the database table, there is a primary key (in our case, an ItemID). The other columns in the table are the colors above (Blue, Green, Red, Brown). Due to the structuring of this data (note: I cannot change it for multiple reasons), I have to create this SQL query in VBA rather than by using what Access provides.
Here is the code I am using to create and run the query when the "Search" button is pressed:
Set qdf = Nothing
*Logic to create SQL query... variable to hold query is called sqlStr*
Set qdf = CurrentDb.CreateQueryDef("TemporaryQuery", sqlStr)
DoCmd.OpenQuery qdf.Name
As a result of much searching, this is the only way I have found, aside from using ADO, that I can create a SQL query IN VBA and then run it in VBA. The downside to this method, while it works, is that it creates a query, which has to be closed and deleted before the query can be ran again. This is not acceptable for the users that will be using this.
All examples I have found (please bear with me) use ADO, which I have not been able to get to work. I have two databases, one for the queries and forms, and one for the data itself. The database containing the data has it's tables linked to the database with the queries and forms. I'm not sure if ADO can work in that setup, but if it can, I haven't been able to figure it out.
Coming from a Java/Webdev background using Access has been a bit frustrating to me as it just seems to be making things more complicated (in my opinion) that it should be. Can anyone help me get this working correctly?
Thank you for your time... it is greatly appreciated!
list boxon a form, you can set theRowsourceproperty oflist boxesto an SQL stringMe.Subform.SourceObject = "sbfSearchAuthorizations"columnsandcolumn widthsoptions.