Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Runtime Error 2108 - Access 2010

    I have 3 fields (ln, fn & dob) whose Required Property is set to Yes. I would like to check the database after entering data in the 3 fields that would alert me if any duplicates being entered.
    I have entered the following code in the BeforeUpdate property of control “dob” that I want to validate before adding a new record.

    Private Sub dob_BeforeUpdate(Cancel As Integer)
    Dim Msg, Style, Title, Response, Counter

    Msg = "A duplicate record may exist." + Chr(13) + "Do you want to add client anyway?" 'Message Displayed
    Style = vbYesNo + vbCritical + vbDefaultButton2 'Define Buttons
    Title = "Duplicate Client Message" 'Define Title
    Response = MsgBox(Msg, Style, Title)
    Counter = DCount("clientid", "client", "fn =" & Chr(34) & Me.[fn] & Chr(34) & _
    " And ln=" & Chr(34) & Me.[ln] & Chr(34) & _
    " And dob=#" & Me.dob & "#")

    If Response = vbNo Then 'User chose No
    Cancel = True
    DoCmd.GoToControl ("ln")
    Else 'User chose Yes
    DoCmd.GoToControl ("gender")
    End If

    End Sub

    No matter whether I choose Yes or No, I continue to get run time error 2108. Can anyone help me correct this?
    Easy Access

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I don't know what error 2108 is. Add an error handler that gives you a description of the error.

    Does using the Setfocus method solve the problem? (as below) That is just a guess..that is now I normally do it.

    Code:
    Private Sub dob_BeforeUpdate(Cancel As Integer)
        Dim Msg, Style, Title, Response, Counter
    
        On Error GoTo dob_BeforeUpdate_Error
    
        Msg = "A duplicate record may exist." + Chr(13) + "Do you want to add client anyway?"    'Message Displayed
        Style = vbYesNo + vbCritical + vbDefaultButton2    'Define Buttons
        Title = "Duplicate Client Message"    'Define Title
        Response = MsgBox(Msg, Style, Title)
        Counter = DCount("clientid", "client", "fn =" & Chr(34) & Me.[fn] & Chr(34) & _
                                             " And ln=" & Chr(34) & Me.[ln] & Chr(34) & _
                                             " And dob=#" & Me.dob & "#")
    
        If Response = vbNo Then    'User chose No
            Cancel = True
            Me.[1n].SetFocus
        Else    'User chose Yes
            Me.[Gender].SetFocus
    
        End If
    
        On Error GoTo 0
        Exit Sub
    
    dob_BeforeUpdate_Error:
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure dob_BeforeUpdate"
    
    End Sub
    Added: If the user chooses No, what do you want to happen? If you set the focus to the 1n control what should happen to the DOB just entered? If you want that date removed you need a me.1n.undo.

    I think (and I don't have time to test this at the moment) that you can't move the focus in a Before Update event. You can't move on until after the update has happened.
    Last edited by johnhutchison; 2011-07-07 at 18:48. Reason: additional thoughts
    Regards
    John



  3. #3
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi John,

    Thanks for the assist. I am still getting the same error message with the SetFocus fix as well. I have included a screenshot of the error message I am getting.2108 Access Error.jpg
    Attached Images Attached Images
    Easy Access

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    This error message confirms (in my mind at least) that the final suggestion in my previous post is the correct explanation.

    You can't use a Before Update to move to another control, because moving to another control means that the update has finished.

    So you need to move some of the code to the After Update event.
    Regards
    John



  5. The Following User Says Thank You to johnhutchison For This Useful Post:

    easyaccess (2011-07-08)

  6. #5
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    Minneapolis, MN, Minnesota
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks John...back to the drawing board
    Easy Access

Posting Permissions

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