Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switchboard Error

Status
Not open for further replies.

czink9

IS-IT--Management
Sep 13, 2005
9
US
I have inherited an Access DB with a switchboard in it and cannot figure out why a menu item that points to a report will not execute. I am pretty sure it revolves around the arguments for the DoCmd.OpenReport. I am pretty new to VB so any help is greatly appreciated. Here is the existing code:

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8

' An error that is special cased.
Const conErrDoCmdCancelled = 2501

Dim dbs As Database
Dim rst As Recordset

On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Switchboard Items", dbOpenDynaset)
rst.FindFirst "[SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn

' If no item matches, report the error and exit the function.
If (rst.NoMatch) Then
MsgBox "There was an error reading the Switchboard Items table."
rst.Close
dbs.Close
Exit Function
End If

Select Case rst![Command]

' Go to another switchboard.
Case conCmdGotoSwitchboard
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rst![Argument]

' Open a form in Add mode.
Case conCmdOpenFormAdd
DoCmd.OpenForm rst![Argument], , , , acAdd

' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rst![Argument]

' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rst![Argument], acViewPreview
 
I really hate using those auto generated switchboards. I would recommend creating one from scratch using an unbound form that opens up at start up but if you want to try a couple of simple tests just to see if you can get what you got functional try

1. Open any form in design view and go to menu VIEW, then CODE. Then see if it the database needs compiling, that would be if COMPILE is an option. Go ahead and compile if necessary (hopefully it just does its thing without any intervention required).

2. Save and close

3. Go to Tools and then Database, then COMPACT and REPAIR (if Access97 or earlier, always always always repair before compacting and never compact a DB that has not been compiled).

Now try your switchboard and see if its fixed.

IF NOT,

4. Go to Switchboard manager and try to locate the problem area, that is what will not open. See if the the named item actually exists in the database window afterward. Compare events of other items that work, ect..
 
Go to Tools>database utilities>switchboard manager. This feature is very easy to use and takes no codeing. Most likely the report that the button is associated with no longer exists or the name has changed. Edit the switchboard item the is associated with opening the report. Find the right report from the pull down.
If all else fails delete the old switchboard and the SwitchBoard Items table. It takes about 30 seconds (for a novice) to add an item to a switchboard. So I think, you have already spent too much time trying to figure out the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top