Results 1 to 2 of 2
  1. #1
    AceD is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    1

    Unhappy Filtering data for any character that begins with what the user input

    Hello everyone I am trying to filter data in a table using vba where I have a split form setup. My goal is to filter data where the user can input a character such as "a" for the "FirstName" field and have results from the table filtered with persons first name that starts with "a". Here is my code so far one of the text boxes.



    Private Sub txtFirstName_DblClick(Cancel As Integer)

    If Me.Filter = "" Then
    'Compares the values that begin with the input values in txtFirstName
    'text box from the table field name FirstName
    Me.Filter = FirstName & " LIKE '" & txtFirstName & "*'"
    Else
    'this line is suppose to append all the filtered data that were acquired
    Me.Filter = Me.Filter & AND LastName & " LIKE '" & txtLastName & "*'"
    End If
    FilterOn = True

    End Sub


    I get a error in the else statement and please note that I am linking this form to an sql server so I can not delete or modify existing data in the table.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You need to get the AND operator within quotes. It is not a variable. You are using the literal text AND. Just like the operator LIKE is within quotes.

    Code:
    Me.Filter = Me.Filter & " AND " & LastName & " LIKE '" & txtLastName & "*'"
    Also, LastName should not be a variable. THis should be a field name in the table/query. so....


    The stuff in red is the literal text you want included in your filter property.
    Code:
    Me.Filter = Me.Filter & " AND [LastName] LIKE '" & txtLastName & "*'"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need different amounts of data depending on a user input?
    By parkerjallen in forum Database Design
    Replies: 2
    Last Post: 11-13-2012, 03:17 PM
  2. Compare Data in a Recordset from User Input
    By hammer187 in forum Programming
    Replies: 9
    Last Post: 09-06-2012, 11:34 AM
  3. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  4. How to take a user input
    By iamraja5 in forum Access
    Replies: 1
    Last Post: 05-12-2011, 10:17 AM
  5. Replies: 9
    Last Post: 10-01-2010, 05:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums