I have a database of magazine articles and I use a "Search" form for the user to build a custom sql select query, kind of a complicated one with lots of joins. The results get passed to a "Search Results" form.
DoCmd.OpenForm "ArticleSearchResultsForm", , , , , , varSQL
Before I pass the results and open the results form, I'd like to first test for any results. If there isn't anything, throw up a MsgBox and exit sub. I was thinking something like this:
If IsNothing(DoCmd.OpenQuery(varSQL)) Then
MsgBox "Sorry, no Articles were found", vbInformation, gstrAppTitle
Exit Sub
End If
varSQL is the complete select query as a string built by the module out of the user's form selections.
Obviously this isn't right though. I guess DoCmd.OpenQuery is looking for an actual saved query. I read one post about having the module write out the dynamic query into the database, run it, and then delete it. Is that the route to go? Any other maybe simpler solutions?
DoCmd.OpenForm "ArticleSearchResultsForm", , , , , , varSQL
Before I pass the results and open the results form, I'd like to first test for any results. If there isn't anything, throw up a MsgBox and exit sub. I was thinking something like this:
If IsNothing(DoCmd.OpenQuery(varSQL)) Then
MsgBox "Sorry, no Articles were found", vbInformation, gstrAppTitle
Exit Sub
End If
varSQL is the complete select query as a string built by the module out of the user's form selections.
Obviously this isn't right though. I guess DoCmd.OpenQuery is looking for an actual saved query. I read one post about having the module write out the dynamic query into the database, run it, and then delete it. Is that the route to go? Any other maybe simpler solutions?