Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    30

    Unanswered: help with search button to disable another command button

    I have a search button programmed and would like to have a button called "cmdeditcustomer" be disabled if no records match the search criteria. I am unsure of what code needs to be written and where it needs to be I know the simple line of code "me.cmdeditcustomer.enabled = false" does the trick but I also know that I would need some sort of a conditional statement for this to work. Here is my code for the search button, I am using Access 07.


    Dim strWhere As String
    Dim lnglen As Long

    If Not IsNull(Me.srchtxtlastname) Then
    strWhere = strWhere & "([Lastname] = """ & Me!srchtxtlastname & """) AND "
    End If

    If Not IsNull(Me.srchtxtfirstname) Then
    strWhere = strWhere & "([Firstname] = """ & Me!srchtxtfirstname & """) AND "
    End If

    If Not IsNull(Me.srchtxtemail) Then
    strWhere = strWhere & "([Email] = """ & Me!srchtxtemail & """) AND "
    End If

    If Not IsNull(Me.srchtxtphone) Then
    strWhere = strWhere & "([Phone] = """ & Me!srchtxtphone & """) "
    End If

    lnglen = Len(strWhere) - 5
    If lnglen <= 0 Then
    MsgBox "No criteria", vbInformation, "Nothing to do."
    Me.cmdeditcustomer.Enabled = False
    Me.cmdregister.Enabled = False
    Else
    strWhere = Left$(strWhere, lnglen)
    Me.cmdeditcustomer.Enabled = True
    Me.cmdregister.Enabled = True
    End If

    Me.Filter = strWhere
    Me.FilterOn = True

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    One way would be to use strWhere in a DCount(), and test the number of records returned.

    By the way, I think you have a logical flaw in your code. If the user enters something in srchtxtphone, your string won't contain a trailing " AND ", yet you still trim it off.
    Paul

  3. #3
    Join Date
    Apr 2011
    Posts
    30

    will do thanks so much

    this is a good suggestion. I will try it out.

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
  •