I would like to assign the contents of a form field to a variable and use that variable as a query parameter when a command button is clicked on the form. So far I have not been successful at making this work. Thanks for your help!
I would like to assign the contents of a form field to a variable and use that variable as a query parameter when a command button is clicked on the form. So far I have not been successful at making this work. Thanks for your help!
It would be simplest to use the form itself in the query criteria. If you want to use a variable, you have to create a function to return its value and call the function from the criteria. You can't refer to a VBA variable directly in a query.
Maybe I have already done what you are suggesting. I currently have the command button set up so that it will open another form based on a query. The query parameter is directed to the field on the original form. I thought that there might be a better way to accomplish this. Doing it the way that I did I had to create 42 additional forms in my database.
I certainly would not create 42 extra forms. I typically have 1 criteria form, used for all reports (I pass the name of the report to be opened in OpenArgs). I've also used a method where I'd copy the value to a hidden textbox on a main menu form that's always open, and have the queries point there. You might also find this method appropriate:
BaldyWeb wherecondition