By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

Navigation AddNew Record woes

P: n/a
Hello and TIA for your consideration.

I have created several db's for a non-profit and they want custom
navigation buttons to display "You are on the first record, last
record, etc". With this ng help I've created code for all except the
add new record command button.

If I create individual sub functions behind each form, no problem.

The problem is I am trying to create a re-usable module.

CBF (works):
Private Sub cmdNewRec_Click()
Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone

If Me.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly, "Data Navigation"
ElseIf Not rs.EOF Then
DoCmd.GoToRecord , , acNewRec
Me.txt_radioNbr.SetFocus
End If

Set rs = Nothing

End Sub

Function (add new record is stepped into but the cursor stays on
current record):
Function NavButtons(strNav As String)
'Purpose: Re-usable module for navigating the form
'Called by: Navigation buttons on forms
'Variables: First, Previous, Next, Last and New
'Returns: Nothing
'Created: Terry Wickenden
Dim frmCurrent As Form
Dim rsNavigate As DAO.Recordset

On Error GoTo ErrNavButtons

Set frmCurrent = Screen.ActiveForm
Set rsNavigate = frmCurrent.RecordsetClone

Select Case strNav
Case "First"
If frmCurrent.CurrentRecord = 1 Then
MsgBox "You are on the first record", vbOKOnly, "Data Navigation"
Else
rsNavigate.MoveFirst
End If
Case "Prev"
If frmCurrent.CurrentRecord = 1 Then
MsgBox "You are on the first record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MovePrevious
End If
Case "Next"
If frmCurrent.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly, "Data
Navigation"

ElseIf frmCurrent.CurrentRecord =
frmCurrent.RecordsetClone.RecordCount Then
MsgBox "You are on the last record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MoveNext
End If
Case "Last"
If frmCurrent.CurrentRecord =
frmCurrent.RecordsetClone.RecordCount Then
MsgBox "You are on the last record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MoveLast
End If
Case "new"
If frmCurrent.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly,
"Data Navigation"
Else
DoCmd.GoToRecord , , acNewRec
End If

End Select
frmCurrent.Bookmark = rsNavigate.Bookmark
Set rsNavigate = Nothing

ExitNavButtons:
Exit Function

ErrNavButtons:
MsgBox Error$
Resume ExitNavButtons

End Function

Again Thanks for any suggestions.
Jul 2 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.