In this post I will be showing you how to automate the controls in the Ribbon.
Featured Videos:
- 05 – Callbacks
Featured Downloads
- AccessRibbon05
05 – Callbacks
The Code
Public Sub OnClick(control As IRibbonControl) Select Case control.id '--------------------------------------------------- '--------------------------------------------------- '----------------Home--------------------------- Case "cmdHome" CloseAllFormsAndReports OpenSingleform "frmHome", Edit, Normal End Select End Sub
Public Function CloseAllFormsAndReports() On Error Resume Next Call CloseAllForms Call CloseAllReports On Error GoTo 0 End Function Public Function CloseAllForms() On Error Resume Next Dim frm As Form Dim i As Integer For i = Application.Forms.count - 1 To 0 Step -1 DoCmd.Close acForm, Forms(i).Name, acSavePrompt Next i On Error GoTo 0 End Function Public Function CloseAllReports() On Error Resume Next Dim rpt As Report Dim i As Integer For i = Application.Reports.count - 1 To 0 Step -1 DoCmd.Close acReport, Reports(i).Name, acSavePrompt Next i On Error GoTo 0 End Function Public Sub OpenSingleform(strFormName As String, strDataMode As DataMode, strWindowMode As WindowMode) On Error Resume Next Call CloseAllFormsAndReports If strDataMode = Add And strWindowMode = Normal Then DoCmd.OpenForm strFormName, , , , acFormAdd, acWindowNormal ElseIf strDataMode = Edit And strWindowMode = Normal Then DoCmd.OpenForm strFormName, , , , acFormEdit, acWindowNormal ElseIf strDataMode = Edit And strWindowMode = Dialog Then DoCmd.OpenForm strFormName, , , , acFormEdit, acDialog End If On Error GoTo 0 End Sub
Related Posts
01 – Introduction to the Ribbon02 – Explanation of the Code
03 – The USysRibbons Table
04 – Tabs, Groups, Buttons and ImageMSOs
06 – Split Buttons
07 – Get Label
08 – Drop Down Menus 1
09 – Drop Down Boxes 2
10 – Splitting a Database