billpennock
Registered User.
- Local time
- Today, 12:43
- Joined
- Aug 10, 2018
- Messages
- 10
I have a form that someone else wrote that takes 3 input fields and uses them to query either a name field or a tag field in a table. It calls a different result form depending on which query but the forms are exactly the same except for the rowsource. I am loath to live with paste code reuse so I'm trying to make it one form and change the rowsource property of the listbox. It doesn't work, I just get no results with any of the following attempts. this seems like it should be easy but either I'm making a stupid mistake or missing something. There are lot's of comments in my code below about what I tried, I'm only trying to get the one query to work now because if that works the other will be trivial
Except that I've seen other posts on other forms saying this should work I am about at the point of making a permanent querydef then deleting it each time, recreating it with the SQL I want and attaching that as the rowsource.
Except that I've seen other posts on other forms saying this should work I am about at the point of making a permanent querydef then deleting it each time, recreating it with the SQL I want and attaching that as the rowsource.
Code:
Private Sub Form_Open(Cancel As Integer)
Dim searchSQL As String
' the following commented out versions of setting searchSQL show what I
' have tried and what works vs what doesn't work. I can't find a version
' of setting searchSQL = that works. forms!frmSearch.txt1 evaluates to
' the string chem in my testing
' this displays the whole table of rows in the listbox of this form
' searchSQL = "select sopid, sopname, soplink from tblSOP"
' this works also just to show it is not only adding a where that kills it
' searchSQL = "select sopid, sopname, soplink from tblSOP where 1=1"
' the next two display empty listbox with no columns
' searchSQL = "select sopid, sopname, soplink from tblSOP where sopName like ""*" & Forms!frmsearch.txt1.Value & "*"""
' debug.print searchSQL = select sopid, sopname, soplink from tblSOP where sopName like "*chem*"
' searchSQL = """select sopid, sopname, soplink from tblSOP where sopName like ""*" & Forms!frmsearch.txt1.Value & "*"""""
' debug.print searchSQL = "select sopid, sopname, soplink from tblSOP where sopName like "*chem*""
resultsList.RowSource = searchSQL
' I have tried resultsList.requery here and also several variations of
' resultslist.recordsourcetype to no avail. A test of the last two searchSQL
' variations using a testSQL(searchSQL) routine works fine showing two records
' in the immediate window. somehow programatically setting rowsource evaluates quotes
' differently than sending it with openrecordset() (used in testsql)
End Sub