"Code": "Private Sub Form_Open(Cancel As Integer)\r\n' Minimize the database window and initialize the form.\r\n\r\n|ONOPENCODE\r\n \r\nEnd Sub\r\n\r\nPrivate Sub Form_Current()\r\n' Update the caption and fill in the list of options.\r\n\r\n Me.Caption = Nz(Me![ItemText], \"\")\r\n FillOptions\r\n \r\nEnd Sub\r\n\r\nPrivate Sub FillOptions()\r\n' Fill in the options for this switchboard page.\r\n\r\n ' The number of buttons on the form.\r\n Const conNumButtons = 8\r\n \r\n Dim con As Object\r\n Dim rs As Object\r\n Dim stSql As String\r\n Dim intOption As Integer\r\n \r\n ' Set the focus to the first button on the form,\r\n ' and then hide all of the buttons on the form\r\n ' but the first. You can't hide the field with the focus.\r\n Me![Option1].SetFocus\r\n For intOption = 2 To conNumButtons\r\n Me(\"Option\" & intOption).Visible = False\r\n Me(\"OptionLabel\" & intOption).Visible = False\r\n Next intOption\r\n \r\n ' Open the table of Switchboard Items, and find\r\n ' the first item for this Switchboard Page.\r\n Set con = Application.CurrentProject.Connection\r\n stSql = \"SELECT * FROM [Switchboard Items]\"\r\n stSql = stSql & \" WHERE [ItemNumber] > 0 AND [SwitchboardID]=\" & Me![SwitchboardID]\r\n stSql = stSql & \" ORDER BY [ItemNumber];\"\r\n Set rs = CreateObject(\"ADODB.Recordset\")\r\n rs.Open stSql, con, 1 ' 1 = adOpenKeyset\r\n \r\n ' If there are no options for this Switchboard Page,\r\n ' display a message. Otherwise, fill the page with the items.\r\n If (rs.EOF) Then\r\n Me![OptionLabel1].Caption = \"|NOITEMS\"\r\n Else\r\n While (Not (rs.EOF))\r\n Me(\"Option\" & rs![ItemNumber]).Visible = True\r\n Me(\"OptionLabel\" & rs![ItemNumber]).Visible = True\r\n Me(\"OptionLabel\" & rs![ItemNumber]).Caption = rs![ItemText]\r\n rs.MoveNext\r\n Wend\r\n End If\r\n\r\n ' Close the recordset and the database.\r\n rs.Close\r\n Set rs = Nothing\r\n Set con = Nothing\r\n\r\nEnd Sub\r\n\r\nPrivate Function HandleButtonClick(intBtn As Integer)\r\n' This function is called when a button is clicked.\r\n' intBtn indicates which button was clicked.\r\n\r\n ' Constants for the commands that can be executed.\r\n Const conCmdGotoSwitchboard = 1\r\n Const conCmdOpenFormAdd = 2\r\n Const conCmdOpenFormBrowse = 3\r\n Const conCmdOpenReport = 4\r\n Const conCmdCustomizeSwitchboard = 5\r\n Const conCmdExitApplication = 6\r\n Const conCmdRunMacro = 7\r\n Const conCmdRunCode = 8\r\n Const conCmdOpenPage = 9\r\n\r\n ' An error that is special cased.\r\n Const conErrDoCmdCancelled = 2501\r\n \r\n Dim con As Object\r\n Dim rs As Object\r\n Dim stSql As String\r\n\r\nOn Error GoTo HandleButtonClick_Err\r\n\r\n ' Find the item in the Switchboard Items table\r\n ' that corresponds to the button that was clicked.\r\n Set con = Application.CurrentProject.Connection\r\n Set rs = CreateObject(\"ADODB.Recordset\")\r\n stSql = \"SELECT * FROM [Switchboard Items] \"\r\n stSql = stSql & \"WHERE [SwitchboardID]=\" & Me![SwitchboardID] & \" AND [ItemNumber]=\" & intBtn\r\n rs.Open stSql, con, 1 ' 1 = adOpenKeyset\r\n \r\n ' If no item matches, report the error and exit the function.\r\n If (rs.EOF) Then\r\n MsgBox \"|READERROR\"\r\n rs.Close\r\n Set rs = Nothing\r\n Set con = Nothing\r\n Exit Function\r\n End If\r\n \r\n Select Case rs![Command]\r\n \r\n ' Go to another switchboard.\r\n Case conCmdGotoSwitchboard\r\n Me.Filter = \"[ItemNumber] = 0 AND [SwitchboardID]=\" & rs![Argument]\r\n \r\n ' Open a form in Add mode.\r\n Case conCmdOpenFormAdd\r\n DoCmd.OpenForm rs![Argument], , , , acAdd\r\n\r\n ' Open a form.\r\n Case conCmdOpenFormBrowse\r\n DoCmd.OpenForm rs![Argument]\r\n\r\n ' Open a report.\r\n Case conCmdOpenReport\r\n DoCmd.OpenReport rs![Argument], acPreview\r\n\r\n ' Customize the Switchboard.\r\n Case conCmdCustomizeSwitchboard\r\n ' Handle the case where the Switchboard Manager\r\n ' is not installed (e.g. Minimal Install).\r\n On Error Resume Next\r\n Application.Run \"ACWZMAIN.sbm_Entry\"\r\n If (Err <> 0) Then MsgBox \"|COMMANDNOTAVAIL\"\r\n On Error GoTo 0\r\n ' Update the form.\r\n Me.Filter = \"[ItemNumber] = 0 AND [Argument] = '|DEFAULT' \"\r\n Me.Caption = Nz(Me![ItemText], \"\")\r\n FillOptions\r\n\r\n ' Exit the application.\r\n Case conCmdExitApplication\r\n CloseCurrentDatabase\r\n\r\n ' Run a macro.\r\n Case conCmdRunMacro\r\n DoCmd.RunMacro rs![Argument]\r\n\r\n ' Run code.\r\n Case conCmdRunCode\r\n Application.Run rs![Argument]\r\n\r\n ' Open a Data Access Page\r\n Case conCmdOpenPage\r\n DoCmd.OpenDataAccessPage rs![Argument]\r\n\r\n ' Any other command is unrecognized.\r\n Case Else\r\n MsgBox \"|UNKNOWNOPTION\"\r\n \r\n End Select\r\n\r\n ' Close the recordset and the database.\r\n rs.Close\r\n \r\nHandleButtonClick_Exit:\r\nOn Error Resume Next\r\n Set rs = Nothing\r\n Set con = Nothing\r\n Exit Function\r\n\r\nHandleButtonClick_Err:\r\n ' If the action was cancelled by the user for\r\n ' some reason, don't display an error message.\r\n ' Instead, resume on the next line.\r\n If (Err = conErrDoCmdCancelled) Then\r\n Resume Next\r\n Else\r\n MsgBox \"|COMMANDERROR\", vbCritical\r\n Resume HandleButtonClick_Exit\r\n End If\r\n \r\nEnd Function"
},
{
"ID": 2,
"Code": "Function IsLoaded(ByVal strFormName As String) As Integer\r\n ' Returns True if the specified form is open in Form view or Datasheet view.\r\n \r\n Const conObjStateClosed = 0\r\n Const conDesignView = 0\r\n \r\n If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then\r\n If Forms(strFormName).CurrentView <> conDesignView Then\r\n IsLoaded = True\r\n End If\r\n End If\r\n \r\nEnd Function"
"Code": " ' Move to the switchboard page that is marked as the default.\r\n Me.Filter = \"[ItemNumber] = 0 AND [Argument] = '|DEFAULT' \"\r\n Me.FilterOn = True"