Results 1 to 4 of 4
  1. #1
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65

    If no match after find first record, do stuff

    Hello experts!



    I run this code under a command button on my Main Menu to find the first record based on criteria in the form that I want to open:

    Code:
    Private Sub Command0_Click()
    If TempVars("CurrentUser") = "admin" Then
    DoCmd.OpenForm "Events"
    Else
    DoCmd.OpenForm "Events"
    Forms("Events").Recordset.FindFirst "Event =" & DLookup("IDevent", "tblEvents", _
    "IDevent=" & "IDevent" & " And [UserName] = '" & TempVars("CurrentUser") & "'")
    'something to add here
    End If
    End Sub

    The code works fine if it finds the current user in the records. If it doesn't find anything, I get an error.
    How can I fix this error?
    I've tried something with NoMatch syntax, but I couldn't achieve much.
    Please help!
    Thx!

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Read about Error Handling in VBA.

  3. #3
    boboivan is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Dec 2015
    Posts
    65
    Thank you cyanidem!

    Fix it!

  4. #4
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270

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

Similar Threads

  1. Replies: 2
    Last Post: 07-27-2015, 06:53 AM
  2. Replies: 4
    Last Post: 07-24-2015, 02:11 AM
  3. Replies: 6
    Last Post: 06-27-2015, 01:38 AM
  4. Replies: 11
    Last Post: 02-06-2014, 10:05 PM
  5. Find an Exact Match in a Access Table column
    By raghavendran in forum Access
    Replies: 4
    Last Post: 10-12-2013, 11:57 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