Next/previous buttons

R

Rob Drummond, Jr

I used a macro to create next record and previous record buttons. When I
reach the last record, a blank form for a new record is loaded then I get the
default message for a macro error and when the first record (for the previous
button) is reached, I get the default message for a macro error. What I
would like is for Next to simply stop and say last record and previous to
stop and no more records. Here is the script for my next record button....

Private Sub RecordNextBtn_Click()
On Error GoTo Err_RecordNextBtn_Click

Dim stDocName As String

stDocName = "RecordNextMcr"
DoCmd.RunMacro stDocName

Exit_RecordNextBtn_Click:
Exit Sub

Err_RecordNextBtn_Click:
MsgBox Err.Description
Resume Exit_RecordNextBtn_Click

End Sub

Any suggestions on how to edit this to NOT create a new record and simply
say no more records (or something similar)?
 
B

Beetle

I would just skip the macro altogether. You don't need it. Modify your
code like this for your Next button;

Private Sub RecordNextBtn_Click()
On Error GoTo Err_RecordNextBtn_Click

If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then
MsgBox "Already at the last record"
Exit Sub
End If

DoCmd.GoToRecord , , acNext

Exit_RecordNextBtn_Click:
Exit Sub

Err_RecordNextBtn_Click:
MsgBox Err.Description
Resume Exit_RecordNextBtn_Click

End Sub


And like this for your Previous button. I have assumed it is called
RecordPreviousBtn. If not you'll need to modify the naming in this example;

Private Sub RecordPreviousBtn_Click()
On Error GoTo Err_RecordPreviousBtn_Click

If Me.CurrentRecord = 1 Then
MsgBox "Already at the first record"
Exit Sub
End If

DoCmd.GoToRecord , , acPrevious

Exit_RecordPreviousBtn_Click:
Exit Sub

Err_RecordPreviousBtn_Click:
MsgBox Err.Description
Resume Exit_RecordPreviousBtn_Click

End Sub
 
R

Rob Drummond, Jr

Perfect, that is exactly what I need. I am very new to Access and know
nothing about SQL so I use "let access do it for you" tools as much as
possible. Thank you so much for the help. NOw if I could just find my other
post to see it got answered I would be set. :)
 
B

Beetle

Here is your other post, along with the answer from fredg;
I am creating a data entry form. I would like to have the cursor
automatically appear in the first field on the form when the "New Record"
button is clicked. How do a set a field as the default or tell the
form/database where to put the cursor when a new record is being created?


1 Code the Form's Current event:
Me.[TheControlName].SetFocus

This will set focus to that control each time you navigate to another
record.

2) If you ONLY wish to do this for a new record entry, then code the
Current event:
If Me.NewRecord Then
Me.TheControlName.SetFocus
End If
 
R

Rob Drummond, Jr

And again, thank you for the help.

Beetle said:
Here is your other post, along with the answer from fredg;
I am creating a data entry form. I would like to have the cursor
automatically appear in the first field on the form when the "New Record"
button is clicked. How do a set a field as the default or tell the
form/database where to put the cursor when a new record is being created?


1 Code the Form's Current event:
Me.[TheControlName].SetFocus

This will set focus to that control each time you navigate to another
record.

2) If you ONLY wish to do this for a new record entry, then code the
Current event:
If Me.NewRecord Then
Me.TheControlName.SetFocus
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top