Forum Discussion
Run a Query without Saving it (to reduce # objects)
- Jan 22, 2025
Okay, so "Like" works, as would other approaches, when working with embedded digits in a larger number.
Yes, I missed out on removing the left square bracket.
To return to the SQL Syntax then ExcelBOA.[Account Number] is a number, not a string of digits in a text field.
Private Sub cmButtonNameGoesHere_Click() Dim strSQL As String strSQL = "SELECT import_Excel_BOA.[As of Date], import_Excel_BOA.Amount," & _ " import_Excel_BOA.[Account Number], " & _ " import_Excel_BOA.[Account Name], import_Excel_BOA.Text " & _ " FROM import_Excel_BOA " & _ " WHERE (import_Excel_BOA.[Account Number] Like ""*"" & [Enter 5213 for VW1 or 5636 for VWMC] & ""*"")" & _ " AND (import_Excel_BOA.Text Like ""*"" & [enter part of co name] & ""*"") ;" Me.ListBoxNameGoesHere.RowSource = strSQL End SubThat's as close as I can get working without data to validate against. I think I got all of the open and close parentheses in the right places, the square brackets where they are needed, and the quotes and double quotes in the right places and numbers.
Hi George, thanks for the reply. I now understand this is not a common thing to do. I might change my approach and save the query but woudl still like to have a workable solution.
To answer your question, i am simply wanting to show the query as a stand alone query. Not in a form...just the dataset as would show as if running a saved query from a form. It is not a subform.
Would I still need a ListBox? I didnt envision using a listbox. thank you.
No, if you just want to open the query for the user to look at, you can use DoCmd.RunSQL strSQL