• Runtime Error 2108 – Access 2010

    Author
    Topic
    #477647

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #1287010

      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.

      • #1287081

        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.28347-2108-Access-Error

    • #1287218

      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.

    Viewing 1 reply thread
    Reply To: Runtime Error 2108 – Access 2010

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: