Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    North Dakota, USA
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What does this error mean? (2000)

    This is a stupid non-descriptive error (see picture). I don't know what's causing it.

    In the after update event of a combo box, I'm opening a new ADO recordset and adding a new record. Once the record is added, I open a form. Then I set the rs variable to nothing. It's on this 'nothing' line that I get the error. Below is the code.


    Private Sub PaymentType_AfterUpdate()

    On Error GoTo Error_PaymentType_AfterUpdate

    Dim rs As New ADODB.Recordset
    Dim intMemberID As Integer
    Dim intMemberYear As Integer
    Dim strPaymentType As String

    intMemberID = Forms!frmmembershipentry!MembershipID
    intMemberYear = Forms!frmmembershipentry!MembershipYear
    strPaymentType = Forms!frmmembershipentry!PaymentType

    rs.Open "tblMemberPaycheckDeduction", CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
    With rs
    .AddNew
    !MembershipID = intMemberID
    !MembershipYear = intMemberYear
    !PaymentType = strPaymentType
    .Update
    .Close
    End With

    DoCmd.OpenForm "subfrmDeduction"

    Set rs = Nothing

    Error_PaymentType_AfterUpdate:
    If Err.Number = -2147217887 Then
    MsgBox "The member name, membership year, and " & _
    "payment type you entered already exist. " & _
    "Please enter a different combination."
    Resume Exit_PaymentType_AfterUpdate
    Else
    MsgBox Err.Number & " " & Err.Description
    End If

    Exit_PaymentType_AfterUpdate:
    Set rs = Nothing
    Exit Sub

    End Sub

    What is the cause of this error?

    Sarah
    Attached Images Attached Images

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What does this error mean? (2000)

    The reason for this error message is that you ALWAYS end up in the error handling section. If no real error occurred, the error number is 0 without a corresponding error message. To avoid this, insert

    GoTo Exit_PaymentType_AfterUpdate

    immediately below the first line

    Set rs = Nothing

  3. #3
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    North Dakota, USA
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What does this error mean? (2000)

    Thanks Hans, that worked.

    I'm still learning this error trapping thing...

    Sarah

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What does this error mean? (2000)

    Hi Sarah,

    Personally, I would order the code slightly differently, to avoid the extra GoTo:

    ...

    DoCmd.OpenForm "subfrmDeduction"

    Exit_PaymentType_AfterUpdate:
    ' Clean up and get out
    Set rs = Nothing
    Exit Sub

    Error_PaymentType_AfterUpdate:
    ' Check for special error
    If Err.Number = -2147217887 Then
    MsgBox "The member name, membership year, and " & _
    "payment type you entered already exist. " & _
    "Please enter a different combination."
    Else
    MsgBox Err.Number & " " & Err.Description
    End If
    ' Always resume at cleaning up section
    Resume Exit_PaymentType_AfterUpdate
    End Sub

  5. #5
    2 Star Lounger
    Join Date
    Jul 2002
    Location
    North Dakota, USA
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What does this error mean? (2000)

    So I must have had the error handler and the exit handler in the wrong order. Exit first then error handler. I turned it around and it also worked fine. Thanks for the tips.

    Sarah

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: What does this error mean? (2000)

    Hi Sarah,

    You can put the error handler first, or the exit handler first, both will work fine if you handle program flow correctly. But if you put the exit handler first, you don't need an extra GoTo statement; it's not a big deal, though.

Posting Permissions

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