Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    65

    Unanswered: NextRecord - how to avoid err message

    I have a control on the form which implements GoToNextRecord event. Currently when the user goes to the last record, and still click on NextRecord, Access opens a blank form (to enter New Record). If you click again, then Access reports some error message.

    I want to avoid these messages if someone is just playing with the DB and clicking randomly.

    Behind the OnClick event of my control (Next Record) is the following code:
    ---------------
    Private Sub NextStudent_Click()
    If Me.StudentId = (Me.Count - 1) Then
    DoCmd.CancelEvent
    MsgBox "This is the last record.", vbInformation + vbOKOnly
    Else:
    DoCmd.GoToRecord acDataForm, "EnterStudents", acNext
    End If
    End Sub
    --------------

    I am sure that (Me.Count-1) is the problem. Here I want to have an expression giving me the latest StudentId (ID with maximum value).

    Any help would be appreciated. Maybe there are other techniques to foolproof this.

    Thanks,
    Jazz

  2. #2
    Join Date
    Jul 2003
    Posts
    81

    Cool Re: NextRecord - how to avoid err message

    Jazz try the easy way of the wizard to add navigation buttons. If you are not ok with the result, try to change the procedure and the error messages. If you have problem send me your mdb.

  3. #3
    Join Date
    Feb 2003
    Posts
    65

    Re: NextRecord - how to avoid err message

    Originally posted by M@sterm!nd
    Jazz try the easy way of the wizard to add navigation buttons. If you are not ok with the result, try to change the procedure and the error messages. If you have problem send me your mdb.
    Thanks for your suggestion. I have been using the wizard for navigation buttons, however they do not give you the message that you have reached the end of your records.

    I found a solution, which now works for me just fine. I will post it here if someone wants to use it:

    ----------
    Private Sub NextRecord_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("YourTableName")

    rs.MoveLast

    If Me.YourFieldId = rs!YourFieldId Then
    MsgBox "This is the last record.", vbInformation + vbOKOnly
    DoCmd.CancelEvent
    Else:
    DoCmd.GoToRecord acDataForm, "YourForm", acNext
    End If
    End Sub
    -----------------

    Jazz

Posting Permissions

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