Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Search As You Type < Combo Box | Import Access >
Back to Search As You Type    Comments List
Upload Images   Link   Email  
Runtime Error 2185
Chris Pardy 
    
8 months ago
Hi, I've tried to integrate this with the older search form method where there are multiple search boxes. In my case I have a textbox that looks at first and Last name, and a combobox that selects a department by ID.. I did note the previous post on this issue and allow additions is set to "on" on the form. the error seems to throw when there is not a result from the input.

Code:

Private Sub RequeryForm()


Dim SQL As String
Dim WHEREstr As String
Dim SORTstr As String
          
        
        WHEREstr = ""
        SORTstr = ""
                  
        If txtNameSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & _
        "PersonelT.FirstName LIKE ""*" & txtNameSearch.Text & "*"" OR " & _
        "PersonelT.LastName LIKE ""*" & txtNameSearch.Text & "*"""
        End If
        '***the error 2185 will highlight the above 3 lines

        If cmbDepSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & "PersonelT.DepartmentID =" & cmbDepSearch
        End If
      
      SQL = "SELECT PersonelT.PersonelID, PersonelT.email, [FirstName]  " & _
            "& "" "" & [LastName] AS FullName, PersonelT.FirstName,  " & _
            "PersonelT.LastName, PersonelT.DepartmentID, PersonelT.DivisionID,  " & _
            "DepartmentT.DepartmentName, PersonelT.FirstName " & _
            "FROM PersonelT INNER JOIN DepartmentT ON PersonelT.DepartmentID  " & _
            "= DepartmentT.DepartmentID"

        If WHEREstr <> "" Then
        SQL = SQL & " WHERE " & WHEREstr
        End If

Me.RecordSource = SQL & SORTstr

End Sub



Private Sub txtNameSearch_Change()

RequeryForm
txtNameSearch.SetFocus
txtNameSearch.SelStart = Len(txtNameSearch.Text)


End Sub

Private Sub cmbDepSearch_AfterUpdate()

RequeryForm

End Sub
Adam Schwanz 
            
8 months ago
This is the problem with line breaks. You need to say WhereStr & "Person... to concatenate, but instead it's using that & symbol as part of the line break instead of as concatenation. I always write them as single line where possible and after confirming it works, go back and break it down.

WHEREstr = WHEREstr & "PersonelT.FirstName LIKE ""*" & txtNameSearch.Text & "*"" OR PersonelT.LastName LIKE ""*" & txtNameSearch.Text & "*"""

The next problem you're going to have is using an OR statement in the middle of a sql statement with AND, you have to put them in parenthesis otherwise it's going to be where first name is like this OR last name AND other stuff.

WHEREstr = WHEREstr & "(PersonelT.FirstName LIKE ""*" & txtNameSearch.Text & "*"" OR PersonelT.LastName LIKE ""*" & txtNameSearch.Text & "*)"""
Chris Pardy OP 
    
8 months ago
Hi Adam.
Now I get Error 3075: Missing ), ], or item in query expression. (PersonelT.FirstName LIKE "*ch*" OR PersonelT.LastName LIKE "*ch*)"

new code:

Private Sub RequeryForm()


Dim SQL As String
Dim WHEREstr As String
Dim SORTstr As String


          
        
        WHEREstr = ""
        SORTstr = ""
        
                
        If txtNameSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & "(PersonelT.FirstName LIKE ""*" & txtNameSearch.Text & "*"" OR PersonelT.LastName LIKE ""*" & txtNameSearch.Text & "*)"""
        End If
        
        If cmbDepSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & "PersonelT.DepartmentID =" & cmbDepSearch & ""
        End If
              
    
      SQL = "SELECT PersonelT.PersonelID, PersonelT.email, [FirstName]  " & _
            "& "" "" & [LastName] AS FullName, PersonelT.FirstName,  " & _
            "PersonelT.LastName, PersonelT.DepartmentID, PersonelT.DivisionID,  " & _
            "DepartmentT.DepartmentName, PersonelT.FirstName " & _
            "FROM PersonelT INNER JOIN DepartmentT ON PersonelT.DepartmentID  " & _
            "= DepartmentT.DepartmentID"

        If WHEREstr <> "" Then
        SQL = SQL & " WHERE " & WHEREstr
        End If

Debug.Print "789 " & SQL & SORTstr

Me.RecordSource = SQL & SORTstr



End Sub



Private Sub txtNameSearch_Change()

RequeryForm

txtNameSearch.SetFocus
txtNameSearch.SelStart = Len(txtNameSearch.Text)


End Sub


Private Sub cmbDepSearch_AfterUpdate()

RequeryForm


End Sub

Adam Schwanz 
            
8 months ago
Sorry, move the parenthesis
"*)"""
to
"*"")"
Chris Pardy OP 
    
8 months ago
Thanks for all the help Adam.. after moving the brackets I still get the sdame error.. however I think I cracked it. I put the setfocus and sel start in the if statement for the cmbDepsearch, and also moved that one up in the order.

Private Sub RequeryForm()


Dim SQL As String
Dim WHEREstr As String
Dim SORTstr As String


          
        
        WHEREstr = ""
        SORTstr = ""
        
        If cmbDepSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & "(PersonelT.DepartmentID =" & cmbDepSearch & ")"
        txtNameSearch.SetFocus
        txtNameSearch.SelStart = Len(txtNameSearch.Text)
        End If
                
                
        If txtNameSearch <> "" Then
        If WHEREstr <> "" Then WHEREstr = WHEREstr & " AND "
        WHEREstr = WHEREstr & "(PersonelT.FirstName LIKE ""*" & txtNameSearch.Text & "*"" OR PersonelT.LastName LIKE ""*" & txtNameSearch.Text & "*"")"
        End If
        
      
      SQL = "SELECT PersonelT.PersonelID, PersonelT.email, [FirstName]  " & _
            "& "" "" & [LastName] AS FullName, PersonelT.FirstName,  " & _
            "PersonelT.LastName, PersonelT.DepartmentID, PersonelT.DivisionID,  " & _
            "DepartmentT.DepartmentName, PersonelT.FirstName " & _
            "FROM PersonelT INNER JOIN DepartmentT ON PersonelT.DepartmentID  " & _
            "= DepartmentT.DepartmentID"

        If WHEREstr <> "" Then
        SQL = SQL & " WHERE " & WHEREstr
        End If

Debug.Print "789 " & SQL & SORTstr

Me.RecordSource = SQL & SORTstr

End Sub

Private Sub txtNameSearch_Change()

RequeryForm
txtNameSearch.SetFocus
txtNameSearch.SelStart = Len(txtNameSearch.Text)

End Sub

Private Sub cmbDepSearch_AfterUpdate()

RequeryForm

End Sub

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Search As You Type.
 

 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 12/13/2024 4:10:27 PM. PLT: 1s