Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Handling (Access 97)

    Let me preface this by saying that any coding I have done has been plagierized. I am very new to coding.
    In an earlier post I stated that while entering data in a shared database, the users occassionally get the following error - "You can't go to the specified record. You may be at the end of a recordset". I received the following reply:

    You can get that by doing a MovePrevious when you're at the first record, or a MoveNext when you are adding a record, i.e. you're trying to move beyond the current records in the table.

    It's error number 2105, so you can check for that number in your error trapping code and just do nothing (leaving you at the start or the end of the recordset as the case may be).

    I would like to do the above but don't know how to code this or what event to use etc. I have the following code that was created when a used the wizard to create a command button

    Private Sub Command20_Click()
    On Error GoTo Err_Command20_Click


    DoCmd.GoToRecord , , acNewRec

    Exit_Command20_Click:
    Exit Sub

    Err_Command20_Click:
    MsgBox Err.Description
    Resume Exit_Command20_Click

  2. #2
    Lounger
    Join Date
    Aug 2001
    Location
    Toronto, Ontario, Canada
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Handling (Access 97)

    Think this should work or something like it. Basically you are trapping the error using an if statement there. You could do what you want with the if, like put in your own custom message box or something.

    HTH

    Private Sub Command20_Click()
    On Error GoTo Err_Command20_Click


    DoCmd.GoToRecord , , acNewRec

    Exit_Command20_Click:
    Exit Sub

    Err_Command20_Click:
    if err.number = 2501
    resume next
    else
    MsgBox Err.Description
    Resume Exit_Command20_Click

    End Sub

  3. #3
    Lounger
    Join Date
    May 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Handling (Access 97)

    Hi Linda...

    First of all, I am assuming that you are using Next and Previous command button controls for navigation on this form right?... If that is not the case let me know...The solution I use to this error message is dealt with in my error trapping code... (I've taken out all the extra code, extra error traps, etc... but this is essentially what you need... I believe...)
    ________________________________________

    Private Sub cmdNext_Click()
    On Error GoTo cmdNext_Err

    DoCmd.GoToRecord , , acNext

    Exit Sub

    cmdNext_Err:

    Select Case Err.Number
    Case 2105
    Call MsgBox("You have reached the end of the selected records... ", vbExclamation, "No Further Records")
    DoCmd.GoToRecord , , acLast
    Resume Next
    End Select
    End Sub
    _______________________________________

    Private Sub cmdPrevious_Click()
    On Error GoTo cmdPrevious_Err

    DoCmd.GoToRecord , , acPrevious

    Exit Sub

    cmdPrevious_Err:

    Select Case Err.Number
    Case 2105
    Call MsgBox("You have reached the beginning of the selected records... ", vbExclamation, "No Previous Records")
    DoCmd.GoToRecord , , acFirst
    Resume Next
    End Select
    End Sub
    _______________________________________

    All this code is doing is allowing the error to occur... and then dealing with the error by sending it to the error trapping code... which will then send a message to the user to let them know they are at EOF or BOF.... and once they click ok on the msgbox... it'll go back to the form at the last or first record accordingly....

    I hope this helps you out... <img src=/S/smile.gif border=0 alt=smile width=15 height=15> ...Personally, I can't believe I am actually replying to a post!!! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> Oh well, if I'm steering you wrong, the wonderful experts on here will set me straight if I am, I'm sure... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    TTFN
    Alexya

  4. #4
    Lounger
    Join Date
    May 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Handling (Access 97)

    Oops... Sorry Donna... Didn't know you had already answered Linda's question... <img src=/S/doh.gif border=0 alt=doh width=15 height=15> lol

    Have a great night! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Alexya

Posting Permissions

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