Results 1 to 4 of 4
  1. #1
    JayRab is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2013
    Posts
    78

    Check to see if data already exists in a query after combobox(in subform) update

    What I want to do is after they select an Equipment ID say 8007 LHD, it looks in the [OPEN EVENTS] Query for that EQ ID. Of course, if it already exists to undo everything and require a close of existing event before moving forward.



    Main form is [Event Dashboard] subform is [Create Event]

    Code:
    Private Sub EQ_ID_AfterUpdate()
    If DCount("*", "[Open Events]", "[EQ ID]'" & Forms![Event Dashboard]![Create Event]![EQ ID]) > 0 Then
        MsgBox "There is already an Active Event for this Equipment.  Please Close existing event before logging another!"
        Me.Undo
              Cancel = True
    End If
    End Sub
    Keep getting syntax errors on this. And not entirely sure on the calling from a subform is right either.

    Thanks for help.

    If anyone knows of a good place that has a list of syntax help that would be awesome as well.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You missed the "=" for starters. Syntax help:

    DLookup Usage Samples

    Forms Refer to Form and Subform properties and controls

    By the way, you can't cancel the after update event, only the before update event. It is, as its name implies, "after" the update has occurred.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JayRab is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Oct 2013
    Posts
    78
    Thanks got it working perfectly now. I appreciate all the help. Thanks for the links as well I have saved them for later use.
    Code:
    Private Sub EQ_ID_AfterUpdate()
    If DCount("*", "[Open Events]", "[EQ ID]='" & Forms![Event Dashboard]![Create Event]![EQ ID] & "'") > 0 Then
        MsgBox "There is already an Active Event for this Equipment.  Please Close existing event before logging another!"
        Me.Undo
    End If
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 10
    Last Post: 10-30-2013, 02:06 PM
  2. Replies: 1
    Last Post: 03-21-2013, 02:14 PM
  3. Check if record exists, Check Number
    By burrina in forum Forms
    Replies: 9
    Last Post: 01-06-2013, 03:49 PM
  4. How to check if Table already exists
    By riaarora in forum Access
    Replies: 1
    Last Post: 08-12-2012, 09:48 AM
  5. Replies: 2
    Last Post: 05-17-2012, 11:19 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