Results 1 to 3 of 3
  1. #1
    yrstruly is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2024
    Posts
    122

    Search Button


    Im trying to implement a search function based on Farm/Client name. Button opens but it does not search and/or gives no action.
    The button filters on this Query
    Code:
    SELECT qryLabClients.ClientID, qryLabClients.ClientName, qryLabClients.Contact, qryLabClients.Tel, qryLabClients.Email, qryLabClients.Initials, qryLabClients.CompNameFROM qryLabClients
    ORDER BY qryLabClients.ClientName;
    The query does produce desired output.
    
    Code:
    Private Sub btnSearch_Click()    Dim s As String
        s = InputBox("Enter full or partial client name to search:", "Search Client")
        
        If s = "" Then
            Me.FilterOn = False
            Exit Sub
        End If
    
    
        ' Use the aliased field name from the query
        Me.Filter = "[ClientName] LIKE '*" & s & "*'"
        Me.FilterOn = True
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Firstly Buttons do no open?

    Learn to walk your code and inspect the variables. Either by hovering over them or printing then in the immediate window with ? s

    ClinetName is not aliased either?

    And
    Code:
    qryLabClients.CompNameFROM
    is not going to work either?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Input boxes are a poor and inefficient means of input for cases like this anyway. A combo with 2 columns, 1st one being bound; clientID (autonumber, hidden) and clientName (short text and visible) would be better. That would also eliminate the need for filtering as there is further inefficiency from loading all records in a form (I suppose the query is the recordsource for the form, and that query has no WHERE clause) and then applying a filter to that. If the combo would have too many records to drop down, then it can be made to filter the list as you type the client name.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 10
    Last Post: 07-07-2017, 05:11 PM
  2. Replies: 1
    Last Post: 11-30-2016, 03:41 AM
  3. Search Button to search entire records VBA
    By excellenthelp in forum Access
    Replies: 5
    Last Post: 06-18-2014, 02:54 PM
  4. Replies: 5
    Last Post: 07-13-2012, 01:15 AM
  5. Replies: 12
    Last Post: 03-22-2012, 02:48 AM

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