Results 1 to 8 of 8
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: trap navigation buttons errors

    I would like to trap the error messages that popped up when the user clicks on the navigation buttons for the previous and next button.

    Error message:
    Run-time error '2105'
    "You can't go to specified record"

    This message appeared when previous button is clicked the current record is the first record or next button is clicked when the current record is already the last record.

    This is the code I wrote for the Previous button but the BOF statment doesn't get executed when it is true. WhY?
    I'm developing in Access 2000 FE and SQL server BE

    Thank you for help!

    Private Sub cmdPrevious_Click()
    Dim rst As New ADODB.Recordset
    On Error GoTo Err_cmdPrevious_Click
    Set rst = Me.Recordset


    If rst.BOF Then
    MsgBox "BOF"
    Else
    DoCmd.GoToRecord , , acPrevious
    End If


    Exit_cmdPrevious_Click:
    Exit Sub

    Err_cmdPrevious_Click:
    'MsgBox Err.Description
    Resume Exit_cmdPrevious_Click

    End Sub

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: trap navigation buttons errors

    Originally posted by alicejwz
    I would like to trap the error messages that popped up when the user clicks on the navigation buttons for the previous and next button.

    Error message:
    Run-time error '2105'
    "You can't go to specified record"

    This message appeared when previous button is clicked the current record is the first record or next button is clicked when the current record is already the last record.

    This is the code I wrote for the Previous button but the BOF statment doesn't get executed when it is true. WhY?
    I'm developing in Access 2000 FE and SQL server BE

    Thank you for help!

    Private Sub cmdPrevious_Click()
    Dim rst As New ADODB.Recordset
    On Error GoTo Err_cmdPrevious_Click

    Set rst = Me.Recordset

    If rst.BOF Then
    MsgBox "BOF"
    Else
    DoCmd.GoToRecord , , acPrevious
    End If

    Exit_cmdPrevious_Click:
    Exit Sub

    Err_cmdPrevious_Click:
    'MsgBox Err.Description
    Resume Exit_cmdPrevious_Click

    End Sub
    One problem that you have is that the forms recordset is going to be a DAO recordset.

    Try this:

    Private Sub cmdPrevious_Click()

    Dim rst As DAO.Recordset
    On Error GoTo Err_cmdPrevious_Click
    Set rst = Me.Recordset


    rst.MovePrevious
    If rst.BOF Then
    rst.MoveFirst
    Exit Sub
    End If

    Exit_cmdPrevious_Click:
    Exit Sub

    Err_cmdPrevious_Click:
    MsgBox Err.Number & vbCrLf & Err.Description
    Resume Exit_cmdPrevious_Click

    End Sub
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  3. #3
    Join Date
    May 2002
    Posts
    395

    trap error and disable navigation button

    Thanks for the great inputs!
    But what I need for example in the previous button if the pointer of the form's recordset moves to first record as the current record I need the Previous button to greyed out or disabled.

    There are two problems with the code I have. The pointer of the recordset must go "beyond" the first record for If rst.bof statement to execute. I need the pointer to stop when at the current record is the first record. Next, the Previous button get greyed out when this occured(within If statement). But I got this message: You can't disable a control while it has focus.

    Thank you very Much!

    Private Sub cmdPrevious_Click()
    Dim rst As New ADODB.Recordset
    On Error GoTo Err_cmdPrevious_Click
    Set rst = Me.Recordset

    rst.MovePrevious

    If rst.BOF Then
    Me!cmdPrevious.Enabled = False
    rst.MoveFirst
    end if

    Exit_cmdPrevious_Click:
    Exit Sub

    Err_cmdPrevious_Click:
    'MsgBox Err.Description
    MsgBox "BOF"
    Resume Exit_cmdPrevious_Click

    End Sub

  4. #4
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Re: trap error and disable navigation button

    Originally posted by alicejwz
    Thanks for the great inputs!
    But what I need for example in the previous button if the pointer of the form's recordset moves to first record as the current record I need the Previous button to greyed out or disabled.

    There are two problems with the code I have. The pointer of the recordset must go "beyond" the first record for If rst.bof statement to execute. I need the pointer to stop when at the current record is the first record. Next, the Previous button get greyed out when this occured(within If statement). But I got this message: You can't disable a control while it has focus.

    Thank you very Much!

    Private Sub cmdPrevious_Click()
    Dim rst As New ADODB.Recordset
    On Error GoTo Err_cmdPrevious_Click
    Set rst = Me.Recordset

    rst.MovePrevious

    If rst.BOF Then
    Me!cmdPrevious.Enabled = False
    rst.MoveFirst
    end if

    Exit_cmdPrevious_Click:
    Exit Sub

    Err_cmdPrevious_Click:
    'MsgBox Err.Description
    MsgBox "BOF"
    Resume Exit_cmdPrevious_Click

    End Sub
    Can't you set focus to the "Next Record" button and disable the "Previous Record" button?

    You will have to set up code to determine when to enable and disable buttons but you could do it in one function or procedure if you wanted. I tried it and it worked for me but I just concentrated on disabling the previous record button.
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  5. #5
    Join Date
    May 2002
    Posts
    395

    Re: trap error and disable navigation button

    Originally posted by basicmek
    Can't you set focus to the "Next Record" button and disable the "Previous Record" button?

    You will have to set up code to determine when to enable and disable buttons but you could do it in one function or procedure if you wanted. I tried it and it worked for me but I just concentrated on disabling the previous record button.
    Could you send me your code(on the previous record button)? I like to see what I did wrong.

    Thanks!!

  6. #6
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Thumbs up Re: trap error and disable navigation button

    Originally posted by alicejwz
    Could you send me your code(on the previous record button)? I like to see what I did wrong.

    Thanks!!
    I'll send you some stuff that you can probably use directly in your application. It's from a CD that came with a book that I have so it's pretty reliable. I'll send a copy of the sample database when I get home tonight if you can wait that long.
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  7. #7
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: trap error and disable navigation button

    Originally posted by alicejwz
    Could you send me your code(on the previous record button)? I like to see what I did wrong.

    Thanks!!
    Here is the sample I promised. It comes from the Access Developers Handbook by Litwin, Getz and Gunderloy.
    Attached Files Attached Files
    Gregg


    DAO, ADO, SQL, Automation and anything else I can pick up.

  8. #8
    Join Date
    May 2002
    Posts
    395

    Re: trap error and disable navigation button

    Originally posted by basicmek
    Here is the sample I promised. It comes from the Access Developers Handbook by Litwin, Getz and Gunderloy.
    Thanks for the sample!
    It looks like it does everything I wanted. I'll see if I can modify it to work for me.

    Thank you very much!
    I'll let you how it turns out.

Posting Permissions

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