UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Keyword Search, Access 2010    
 
   
jonanem
post Oct 14 2019, 05:12 AM
Post#1



Posts: 1
Joined: 14-October 19



I have two buttons on ‘frmCustomerListForNewEnquiry’- the ‘search button’ works as a keyword search, the ‘command button’ will respond if ‘txtCustomerSearch’ is either left blank or has ‘rubbish’ typed into it. I am trying to combine them into a single button using an if statement but my brain is too full of wishy washy thinking. Any suggestions would be much appreciated- thanks in advance,
jonanem

Attached File(s)
Attached File  SampleDB.zip ( 296.46K )Number of downloads: 15
 
Go to the top of the page
 
arnelgp
post Oct 14 2019, 05:34 AM
Post#2



Posts: 1,510
Joined: 2-April 09
From: somewhere out there...


i think no need for 2nd button, btnCustomerSearch is sufficient:
CODE
Private Sub btnCustomerSearch_Click()
   Dim SQL  As String

    If Len(Trim(Me.txtCustomerSearch & "")) = 0 Then
        MsgBox "Nothing to search. Please type the customer name or contact name."
        Me.txtCustomerSearch.SetFocus
        Exit Sub
    Else
        If Nz(DCount("1", "tblCustomer", "[CustomerName] LIKE '*" & Me.txtCustomerSearch _
         & "*'" & "OR [ContactName] LIKE '*" & Me.txtCustomerSearch _
         & "*'"), 0) = 0 Then
            MsgBox "No match. Please check your spelling or click on the New Customer button"
            Me.txtCustomerSearch.SetFocus
            Exit Sub
    End If
    
     SQL = "SELECT tblCustomer.CustomerID, tblCustomer.CustomerName, tblCustomer.ContactName," _
         & "tblCustomer.CustomerAddressFirstLine, tblCustomer.CustomerAddressSecondLine, " _
         & "tblCustomer.CustomerTown, tblCustomer.CustomerCounty, tblCustomer.CustomerPostCode," _
         & "tblCustomer.CustomerPhone, tblCustomer.CustomerMobile " _
         & "FROM tblCustomer " & "WHERE [CustomerName] LIKE '*" & Me.txtCustomerSearch _
         & "*'" & "OR [ContactName] LIKE '*" & Me.txtCustomerSearch _
         & "*'" & "ORDER BY tblCustomer.CustomerName"
    
        Me.subCustomerListForNewEnquiry.Form.RecordSource = SQL
        Me.subCustomerListForNewEnquiry.Requery
    

  
End Sub

This post has been edited by arnelgp: Oct 14 2019, 05:35 AM

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th November 2019 - 07:31 PM