I use the same buttons in almost all of my forms none of them change is there a way of only having to write the code once and reference it on all of them so that if I change it! the all change
here is the code that is looped
Of course the only part that would probably change would be the form name in this example its Critical_Criteria in another it would be Inbound ext...
here is the code that is looped
Code:
Private Sub Previous_Record_Click() 'Button
On Error GoTo Err_Previous_Record_Click
DoCmd.GoToRecord , , acPrevious
Exit_Previous_Record_Click:
Exit Sub
Err_Previous_Record_Click:
MsgBox Err.Description
Resume Exit_Previous_Record_Click
End Sub
Private Sub Next_Record_Click() 'Button
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Exit_Next_Record_Click:
Exit Sub
Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click
End Sub
Private Sub New_Record_Click() 'Button
On Error GoTo Err_New_Record_Click
DoCmd.GoToRecord , , acNewRec
Exit_New_Record_Click:
Exit Sub
Err_New_Record_Click:
MsgBox Err.Description
Resume Exit_New_Record_Click
End Sub
Private Sub DeleteRecord_DblClick(Cancel As Integer) 'Button
On Error GoTo Err_DeleteRecord_Click
DoCmd.RunCommand acCmdDeleteRecord
Exit_DeleteRecord_Click:
Exit Sub
Err_DeleteRecord_Click:
MsgBox Err.Description
Resume Exit_DeleteRecord_Click
End Sub
Private Sub Print_Preview_Click() 'Button
On Error GoTo Err_Print_Preview_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Critical_Criteria_Report"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acPreview, , "[Critical_Criteria.tblInitials] = """ & Me.tblInitials & """ And [tblCritical_Criteria_ID] = " & tblCritical_Criteria_ID
Exit_Print_Preview_Click:
Exit Sub
Err_Print_Preview_Click:
MsgBox Err.Description
Resume Exit_Print_Preview_Click
End Sub
Private Sub Email_Critical_Criteria_Report_Click()
On Error GoTo Err_Email_Critical_Criteria_Report_Click
If [Forms]![Critical_Criteria]![tblEmp_First_Name] <> "" Then
DoCmd.OpenForm "CC_Email", , , , , , Me.Name
Else
Dim Msg, Style, Title, Response
Msg = Me.tblInitials & " report does not contain a First Name!" & _
Chr(13) & Chr(13) & "Continue?"
Style = vbExclamation + vbYesNo
Title = "Error!"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
DoCmd.OpenForm "CC_Email", , , , , , Me.Name
Else ' User chose No.
End If
End If
Exit_Email_Critical_Criteria_Report_Click:
Exit Sub
Err_Email_Critical_Criteria_Report_Click:
MsgBox Err.Description
Resume Exit_Email_Critical_Criteria_Report_Click
End Sub
Private Sub Save_Record_Click() 'Button
On Error GoTo Err_Save_Record_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_Save_Record_Click:
Exit Sub
Err_Save_Record_Click:
MsgBox Err.Description
Resume Exit_Save_Record_Click
End Sub
Private Sub CloseForm_Click() 'Button
On Error GoTo Err_CloseForm_Click
DoCmd.Close
Exit_CloseForm_Click:
Exit Sub
Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click
End Sub
Of course the only part that would probably change would be the form name in this example its Critical_Criteria in another it would be Inbound ext...
Last edited: