Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2013
    Posts
    10

    Unanswered: How do I tell if a query returns 0 records?

    Hi Folks,
    Sorry for the bonehead question -- I'm new to Access 2010. I've created a 'parameter' query to seek a single record (username & password) plus other info in the password file. If both fields on the form aren't found, login is supposed to fail (with msgbox).
    So, how can I programmatically determine if my query returned 0 records from VBA? I'm using a DoCmd.OpenQuery in VBA, but can't figure out how to read or use the data from the resulting 'datasheet'.
    My old Access skills are a bit rusty, and Acc2010 has got me all confused. Any help is better than MS's. Thanks!
    --Dawg

  2. #2
    Join Date
    Nov 2011
    Posts
    413
    If Me.Recordset.RecordCount = 0 Then
    MsgBox "Sorry, Username Not Found"
    End If

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or consider using the dlookup function
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Apr 2013
    Posts
    10
    Thanx Burrina. Now I've got to educate myself on Recordset(s) properties. Something about Object Definitions? If you've got a quick answer, I'd appreciate it. I told you I was rusty!
    --Dawg

  5. #5
    Join Date
    Nov 2011
    Posts
    413
    If you want to determine if there are NO records found in the table, then this is what will do the trick. Below is an example of using the DLookup as Healdem said.

    HTH

    If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.txtUserID.Value & "' And [pw]='" & Me.txtPW.Value & "'")) Then
    MsgBox "Your User ID and Password do not match." & vbCrLf & vbCrLf & _
    "Please try again.", vbCritical + vbOKOnly, "Oops!"
    Last edited by Burrina; 09-05-13 at 16:35. Reason: Further Explanation.

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
  •