Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008
    Posts
    28

    Question Unanswered: Trap/Catch no records found?

    Access 2003 ADP connected to a SQL 2005 Server.

    Ok, I have a simple form to look up static data from a retired server. I use a text field so a user can apply a custom server filter.

    Code:
    Private Sub cmdSearchHealth_Click()
    
        If Me.txtSearchHealth <> "" Then
            Me.ServerFilter = "HEALTHNO = '" & Me.txtSearchHealth & "'"
            Me.Requery
        End If
      
    End Sub
    Very simple and it works. My problem is that if you search against text that is not found then all objects on the form disappear. I need a way to check if no records are found so that I can 1. display a message to the user and 2. reset the filter so that the form doesn't leave to lunch.

    Any Ideas?

    Thanks,
    Yul

  2. #2
    Join Date
    Mar 2008
    Posts
    28
    NM...figured it out. I eventually found the DCount function.

    This worked great:

    Code:
    Dim m As Integer
    
        If Me.txtSearchHealth <> "" And DCount("HEALTHNO", "MAIN", "HEALTHNO = '" & Me.txtSearchHealth & "'") > 0 Then
            Me.ServerFilter = "HEALTHNO = '" & Me.txtSearchHealth & "'"
            Me.Requery
        Else
            m = MsgBox("No Records Found", vbInformation, "Search Results")
        End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •