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.


|