Results 1 to 8 of 8

Thread: error handling

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error handling

    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

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error handling

    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.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: error handling

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

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

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: error handling

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


    <pre>MySet.FindFirst "[Receipt#] = '" & Me.Text28 & "'"</pre>

    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error handling

    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..

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: error handling

    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.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error handling

    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.
    Attached Images Attached Images

  8. #8
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Winnipeg, Canada
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: error handling

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

Posting Permissions

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