Connecting Tech Pros Worldwide Help | Site Map

Navigation AddNew Record woes

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 2nd, 2008, 11:15 PM
emalcolm_FLA@comcast.net
Guest
 
Posts: n/a
Default Navigation AddNew Record woes

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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.