I'm trying to set up a search on a form that has a pass through query as the Record Source but I'm confused on how to use that pass through query on the open form since it is the Record Source.
I originally used one of the old classes on searches but that is not giving me a smooth search.
If you take your test database example and pass it the customer list filtered by FL. How can you add a search box on the customer list to search on first names.
Do I need to create a record set for the pass through query? Hope this makes sense.
Sami Shamma
@Reply 18 months ago
What you need to do is to build the passthrough query SQL statement on the fly.
In the morning, I will try to find the video in which Richard shows how to do that.
Todd ClappOP
@Reply 18 months ago
Thanks Sami for the response! I did find the video for making the passthrough query SQL on the fly but will that work if you are writing the query from sql server? I need to figure that out.
I did sorta get another way to work using recordsets and I keep getting an error "The object you entered is not a valid Recordset property". This is so frustrating because I ran a test using msgbox and I can get the results I want when I type a letter into the searchbox. UGH. I need to step away for a little while.
Sami Shamma
@Reply 18 months ago
Yes it will.
Show the error massage
Todd ClappOP
@Reply 18 months ago
I stripped out a lot of detail but the part where it fails is setting the recordset. That is the part I'm having a hard time grasping.
Dim conn, rs, MySQL
Dim txtSearch As String
Dim strFilter As String
Dim divID
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
conn.Open TempVars("ADOConnectString")
' Get the text entered in SearchBox
txtSearch = Me.SearchBox.Text
' Construct the dynamic filter
If txtSearch <> "" Then
strFilter = " tblEntity.EntityCode LIKE '%" & txtSearch & "%' "
End If
' Build the SQL query incorporting the dynamic filter
MySQL = "SELECT tblEntity.EntityID, tblEntity.EntityCode, " & _
"CONCAT(tblEntity.FirstName, ' ', tblEntity.LastName) AS DisplayName " & _
"FROM tblEntity " & _
"WHERE " & strFilter & _
"ORDER BY tblEntity.EntityCode;"
Also, properly dim all your variables. For example,
dim rs as RecordSet.
Todd ClappOP
@Reply 18 months ago
I started over and figured it out by creating a new query on the fly and searching on that. Working fine :)
Only thing I hate about it is the cursor jump that happens when the searchTextBox gets focus and you have to find the length of the string and place the cursor at the end. Any idea how to get past that?
Sami Shamma
@Reply 18 months ago
Sorry Todd, but I can't envision what you're talking about regarding the search text box. Can you please elaborate?
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access SQL Server Lessons.