• Error Handling (Access 97)

    Author
    Topic
    #363177

    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

    Viewing 2 reply threads
    Author
    Replies
    • #553617

      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

    • #553618

      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… smile …Personally, I can’t believe I am actually replying to a post!!! laugh Oh well, if I’m steering you wrong, the wonderful experts on here will set me straight if I am, I’m sure… smile

      TTFN
      Alexya

    • #553619

      Oops… Sorry Donna… Didn’t know you had already answered Linda’s question… doh lol

      Have a great night! smile
      Alexya

    Viewing 2 reply threads
    Reply To: Error Handling (Access 97)

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

    Your information: