• error handling

    Author
    Topic
    #353485

    Need help handling errors with this code. Any help is greatly appreciated.. This code searches and updates a field called Receipt# if the entered value is in the query it works fine if not the de###### opens and I get a runtime error 2427.. It highights the line MySet.FindFirst “[Receipt#] = ” & “‘” & Not sure what the problem is.. Is there a way to handle this error.. Thanks..

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim MyDB As DAO.Database
    Dim MySet As DAO.Recordset
    Set MyDB = CurrentDb()
    ‘Update this receipt number record
    Set MySet = MyDB.OpenRecordset(“ReceiptNumbers”, dbOpenDynaset)
    MySet.MoveFirst
    MySet.FindFirst “[Receipt#] = ” & “‘” & Me.Text28 & “‘”

    If MySet.NoMatch Then
    MsgBox (“Receipt# ” & Me.Text28 & ” not found.”)
    Else
    MySet.Edit
    MySet(“Group#”) = newSeqNo
    MySet.Update
    End If
    MySet.Close
    Set MySet = Nothing
    Set MyDB = Nothing

    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #517200

      Howdy g,

      Have you tried:
      MySet.FindFirst “[Receipt#] = “”” & Me.Text28 & “”””

      One, three and four quote chars.

      For error handling, try this:
      Immediately after you Dim statements enter:

      On Error Goto ErrorHandler

      And copy this code to line before End Sub

      Cleanup:
      MySet.Close
      Set MySet = Nothing
      Set MyDB = Nothing
      Exit Sub
      ErrorHandler:
      MsgBox “Error: ” & Err.Description & ” (” & Err.Number & “)”
      Resume Cleanup

      See if it works.

      • #517220

        If you’re looking for a text value, the simplest way to handle it is this:

        MySet.FindFirst “[Receipt#] = ‘” & Me.Text28 & “‘”

        • #517221

          Hmm, that isn’t very readable. Let’s try again:

          MySet.FindFirst "[Receipt#] = '" & Me.Text28 & "'"
          • #517252

            Ken your error handling works well.. But when I tried each of the new line of code you gave me it still gives me the same 2427 error “You entered data that has no value.” It has a real problem if the it kind find what you enter.. Any thing else we could try? Thanks..

            • #517267

              If you break into the code and hover the mouse pointer over your Me.Text38, what do you see? If it tells you the value of Me.Text38 is null, that may be the problem. If you see an error string in the popup tip, you’re referencing something that Access can’t recognize.

              If the problem is the latter, first substitute Me!Text38 for Me.Text38. That will at least tell Access that you’re working with a control and not a method or property. Then, make sure you actually have a textbox called Text38 on your form. I’m assuming that you don’t have an underlying field called Text38, since that would be highly unlikely.

            • #517269

              Hi,

              This is an interesting problem, because I just setup a little table with Receipt# and Group# as fields, referenced DAO 3.6 and made a small form with a textbox (Text28) and a commandbutton to run your code as copied from your post, and I CAN’T make it fail.

              The only thing I had to add was a DIM statement for newSeqNo and assign a value to it. It worked perfectly each time. Even with no data in the text box, it worked fine.

              I’ll have to look into error 2427 a bit more.

            • #517270

              I am adding the rest of the screen shots. Maybe it will trigger something for you.
              It doesn’t appear to be your code.

    Viewing 0 reply threads
    Reply To: error handling

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

    Your information: