Search box

josros60

Registered User.
Local time
Today, 09:15
Joined
Mar 10, 2011
Messages
73
I found a form in the web downloaded,

but when I search for a company get an error and highlight one line:

Here it's the code:

Code:
Private Sub cmdSearch_Click()

    Dim LSQL  As String
    Dim LSearchString As String
    
    If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
        MsgBox "You must enter a search string."
        
    Else
    
        LSearchString = txtSearchString
        
        'Filter results based on search string
        LSQL = "select * from tblVendor"
        LSQL = LSQL & " where Vendor Name LIKE '*" & LSearchString & "*'"
        
     Form_frmVendor_sub.RecordSource = LSQL
        
        lblTitle.Caption = "Vendor Details:  Filtered by '" & LSearchString & "'"
        
        'Clear search string
        txtSearchString = ""
        
        MsgBox "Results have been filtered.  All Vendor Names containing " & LSearchString & "."
        
    End If
    
End Sub

But the line it highlight is:

Code:
Form_frmVendor_sub.RecordSource = LSQL


Thanks.
 
1. you usually put a letter at the start of the variable to identify what type of variable type it is.
Dim sSQL As String
dim iNum as integer

2. don't redo the sql to find things, just use a filter on a continuous list form,
and the only code needed is
Code:
 Private Sub cmdSearch_Click()
    me.filter = "[Vendor] like *" & txtSearchString & "*"
    me.filterOn=true
 end sub
then just turn the filter off from the toolbar
 
thanks.

How do I turn the filter off from the toolbar?

Access 2013.

thanks.
 
Your error is likely due to the inadvisable space in the field name. It needs to be bracketed.
 
LSQL = LSQL & " where [Vendor Name] LIKE '*" & LSearchString & "*'"
 

Users who are viewing this thread

Back
Top Bottom