Well, put the code to set control properties in a Sub and call that Sub instead of repeating code. The Sub can have an argument passed to it.
Coding for custom navigation buttons is a common topic. Example from my db.
Code:
Public Sub ViewData(strDirection)
'called by forms used to view and navigate records
If Not IsNull(Form_SampleInfo.tbxViewDataFormNAME) Then
DoCmd.Close acForm, Form_SampleInfo.tbxViewDataFormNAME, acSaveNo
End If
With Form_SampleInfo
.RecordsetClone.Bookmark = .Bookmark
Select Case strDirection
Case "Quit"
DoCmd.Close acForm, "SampleInfo", acSaveNo
Case "Next"
.RecordsetClone.MoveNext
If Not .RecordsetClone.EOF Then
DoCmd.GoToRecord acForm, "SampleInfo", acNext
Else
.RecordsetClone.MoveLast
MsgBox "Last record."
.btnNext.Enabled = False
End If
.btnPrevious.Enabled = True
Case "Previous"
.RecordsetClone.MovePrevious
If Not .RecordsetClone.BOF Then
DoCmd.GoToRecord acForm, "SampleInfo", acPrevious
Else
.RecordsetClone.MoveFirst
MsgBox "First record."
.btnPrevious.Enabled = False
End If
.btnNext.Enabled = True
End Select
End With
End Sub
Calling Sub:
Code:
Private Sub btnNext_Click()
Me.btnViewLabData.SetFocus
Call ViewData("Next")
End Sub
Private Sub btnPrevious_Click()
Me.btnViewLabData.SetFocus
Call ViewData("Previous")
End Sub
Private Sub btnQuit_Click()
Call ViewData("Quit")
End Sub