Switchboard

T

TomGarrett

Our production manager (now deceased) had created an access database on a
stand alone pc - He created a switchboard for this database. When I point
other users accross the network to see this database some of the sub forms do
not work.

I moved a copy of this database to my pc and get the following error from
Microsoft Visual Basic -

Run-time error'2147221164(80040154)':
Class not registered

When I press the debug the following code is displayed and the line that
reads the following is in yellow

rs.open stsql, con, 1 ' 1 = adOpenKeyset

Actual code follows -
Option Compare Database

Private Sub Detail_Click()
DoCmd.OpenForm "frmInactiveShutown", , , , , acHidden
End Sub

Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub

Private Sub Form_Current()
' Update the caption and fill in the list of options.

Me.Caption = Nz(Me![ItemText], "")
FillOptions

End Sub

Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.
Const conNumButtons = 8

Dim con As Object
Dim rs As Object
Dim stSql As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me!
[SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub

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
Const conCmdOpenPage = 9

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

Dim con As Object
Dim rs As Object
Dim stSql As String

On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [Switchboard Items] "
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND
[ItemNumber]=" & intBtn
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If no item matches, report the error and exit the function.
If (rs.EOF) Then
MsgBox "There was an error reading the Switchboard Items table."
rs.Close
Set rs = Nothing
Set con = Nothing
Exit Function
End If

Select Case rs![Command]

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

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

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

' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rs![Argument], acPreview

' Customize the Switchboard.
Case conCmdCustomizeSwitchboard
' Handle the case where the Switchboard Manager
' is not installed (e.g. Minimal Install).
On Error Resume Next
Application.Run "ACWZMAIN.sbm_Entry"
If (err <> 0) Then MsgBox "Command not available."
On Error GoTo 0
' Update the form.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.Caption = Nz(Me![ItemText], "")
FillOptions

' Exit the application.
Case conCmdExitApplication
CloseCurrentDatabase

' Run a macro.
Case conCmdRunMacro
DoCmd.RunMacro rs![Argument]

' Run code.
Case conCmdRunCode
Application.Run rs![Argument]

' Open a Data Access Page
Case conCmdOpenPage
DoCmd.OpenDataAccessPage rs![Argument]

' Any other command is unrecognized.
Case Else
MsgBox "Unknown option."

End Select

' Close the recordset and the database.
rs.Close

HandleButtonClick_Exit:
On Error Resume Next
Set rs = Nothing
Set con = Nothing
Exit Function

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

End Function

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click


DoCmd.Quit

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox err.Description
Resume Exit_Command24_Click

End Sub

Private Sub exit_app_Click()
On Error GoTo Err_exit_app_Click


DoCmd.Quit

Exit_exit_app_Click:
Exit Sub

Err_exit_app_Click:
MsgBox err.Description
Resume Exit_exit_app_Click

End Sub
 
N

NevilleT

The first place I would look if you are getting different results on
different PCs is the references. Find one that works, and in the VBA window
go to tools references. See what is ticked and the order. Now go to one
that doesnt and do the same. Maybe there is a missing reference. Suspect it
might be an ADO reference.

TomGarrett said:
Our production manager (now deceased) had created an access database on a
stand alone pc - He created a switchboard for this database. When I point
other users accross the network to see this database some of the sub forms do
not work.

I moved a copy of this database to my pc and get the following error from
Microsoft Visual Basic -

Run-time error'2147221164(80040154)':
Class not registered

When I press the debug the following code is displayed and the line that
reads the following is in yellow

rs.open stsql, con, 1 ' 1 = adOpenKeyset

Actual code follows -
Option Compare Database

Private Sub Detail_Click()
DoCmd.OpenForm "frmInactiveShutown", , , , , acHidden
End Sub

Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub

Private Sub Form_Current()
' Update the caption and fill in the list of options.

Me.Caption = Nz(Me![ItemText], "")
FillOptions

End Sub

Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.
Const conNumButtons = 8

Dim con As Object
Dim rs As Object
Dim stSql As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me!
[SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub

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
Const conCmdOpenPage = 9

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

Dim con As Object
Dim rs As Object
Dim stSql As String

On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [Switchboard Items] "
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND
[ItemNumber]=" & intBtn
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If no item matches, report the error and exit the function.
If (rs.EOF) Then
MsgBox "There was an error reading the Switchboard Items table."
rs.Close
Set rs = Nothing
Set con = Nothing
Exit Function
End If

Select Case rs![Command]

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

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

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

' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rs![Argument], acPreview

' Customize the Switchboard.
Case conCmdCustomizeSwitchboard
' Handle the case where the Switchboard Manager
' is not installed (e.g. Minimal Install).
On Error Resume Next
Application.Run "ACWZMAIN.sbm_Entry"
If (err <> 0) Then MsgBox "Command not available."
On Error GoTo 0
' Update the form.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.Caption = Nz(Me![ItemText], "")
FillOptions

' Exit the application.
Case conCmdExitApplication
CloseCurrentDatabase

' Run a macro.
Case conCmdRunMacro
DoCmd.RunMacro rs![Argument]

' Run code.
Case conCmdRunCode
Application.Run rs![Argument]

' Open a Data Access Page
Case conCmdOpenPage
DoCmd.OpenDataAccessPage rs![Argument]

' Any other command is unrecognized.
Case Else
MsgBox "Unknown option."

End Select

' Close the recordset and the database.
rs.Close

HandleButtonClick_Exit:
On Error Resume Next
Set rs = Nothing
Set con = Nothing
Exit Function

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

End Function

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click


DoCmd.Quit

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox err.Description
Resume Exit_Command24_Click

End Sub

Private Sub exit_app_Click()
On Error GoTo Err_exit_app_Click


DoCmd.Quit

Exit_exit_app_Click:
Exit Sub

Err_exit_app_Click:
MsgBox err.Description
Resume Exit_exit_app_Click

End Sub
 
T

TomGarrett via AccessMonster.com

Neville -
I did try that in addition I also made sure that I copied the references to
the same locations (directories) as was on his PC.

That still did not seem to help. Any other ideas you might have would be
greatly appreciated.
The first place I would look if you are getting different results on
different PCs is the references. Find one that works, and in the VBA window
go to tools references. See what is ticked and the order. Now go to one
that doesnt and do the same. Maybe there is a missing reference. Suspect it
might be an ADO reference.
Our production manager (now deceased) had created an access database on a
stand alone pc - He created a switchboard for this database. When I point
[quoted text clipped - 232 lines]
 
N

NevilleT

Hi Tom

I assume the references are in the same order on both machines.

Neville

TomGarrett via AccessMonster.com said:
Neville -
I did try that in addition I also made sure that I copied the references to
the same locations (directories) as was on his PC.

That still did not seem to help. Any other ideas you might have would be
greatly appreciated.
The first place I would look if you are getting different results on
different PCs is the references. Find one that works, and in the VBA window
go to tools references. See what is ticked and the order. Now go to one
that doesnt and do the same. Maybe there is a missing reference. Suspect it
might be an ADO reference.
Our production manager (now deceased) had created an access database on a
stand alone pc - He created a switchboard for this database. When I point
[quoted text clipped - 232 lines]
 
T

TomGarrett via AccessMonster.com

Thanks for working with me on this Neville -
The references were not in the same order but I have now corrected that issue.
The only difference with regards to references is that the 2nd one in line is
Microsoft Access 9.0 Object Library and my system shows it as Microsoft
Access 11.0 Object Library.

I did try to copy the 9.0 library and location from the original PC to mine
and then I tried to browse and point to the 9.0 version but access will not
update the reference with the 9.0.
Hi Tom

I assume the references are in the same order on both machines.

Neville
Neville -
I did try that in addition I also made sure that I copied the references to
[quoted text clipped - 14 lines]
 
N

NevilleT

It usually doesn't matter about versions, as long as they are in the same
order. For example if DAO is before ADO, it will try and use DAO first and
that can sometimes cause problems. Is there any correlation between the
versions, and what works or doesn't? For example, do all version 11s work
and version 9s not work?
It sounds like something simple in the Access setup so I would be looking
for common differences in working and non working installations. One
question I forgot to ask is if you are using Access or SQL Server for the
database? If SQL Server it might be at that end the problem is occuring.
Different users with different permissions on a table.
If it is a simple Access database, maybe you can forward a copy to me and I
can have a look.
Can be frustrating when you get this sort of error.

TomGarrett via AccessMonster.com said:
Thanks for working with me on this Neville -
The references were not in the same order but I have now corrected that issue.
The only difference with regards to references is that the 2nd one in line is
Microsoft Access 9.0 Object Library and my system shows it as Microsoft
Access 11.0 Object Library.

I did try to copy the 9.0 library and location from the original PC to mine
and then I tried to browse and point to the 9.0 version but access will not
update the reference with the 9.0.
Hi Tom

I assume the references are in the same order on both machines.

Neville
Neville -
I did try that in addition I also made sure that I copied the references to
[quoted text clipped - 14 lines]
 
T

TomGarrett via AccessMonster.com

Neville -
It is not a complex access database but not very simple either - I would be
happy to forward you a copy of the database. How do I get the database to
you? Do you want me to place it in a zip file?
It usually doesn't matter about versions, as long as they are in the same
order. For example if DAO is before ADO, it will try and use DAO first and
that can sometimes cause problems. Is there any correlation between the
versions, and what works or doesn't? For example, do all version 11s work
and version 9s not work?
It sounds like something simple in the Access setup so I would be looking
for common differences in working and non working installations. One
question I forgot to ask is if you are using Access or SQL Server for the
database? If SQL Server it might be at that end the problem is occuring.
Different users with different permissions on a table.
If it is a simple Access database, maybe you can forward a copy to me and I
can have a look.
Can be frustrating when you get this sort of error.
Thanks for working with me on this Neville -
The references were not in the same order but I have now corrected that issue.
[quoted text clipped - 17 lines]
 
N

NevilleT

Hi Tom

Send it to me at (e-mail address removed) as a zip. May not look at it
until Tuesday our time. Monday is a public holiday in Australia. Request a
read receipt and I will let you know I received it.

Neville

TomGarrett via AccessMonster.com said:
Neville -
It is not a complex access database but not very simple either - I would be
happy to forward you a copy of the database. How do I get the database to
you? Do you want me to place it in a zip file?
It usually doesn't matter about versions, as long as they are in the same
order. For example if DAO is before ADO, it will try and use DAO first and
that can sometimes cause problems. Is there any correlation between the
versions, and what works or doesn't? For example, do all version 11s work
and version 9s not work?
It sounds like something simple in the Access setup so I would be looking
for common differences in working and non working installations. One
question I forgot to ask is if you are using Access or SQL Server for the
database? If SQL Server it might be at that end the problem is occuring.
Different users with different permissions on a table.
If it is a simple Access database, maybe you can forward a copy to me and I
can have a look.
Can be frustrating when you get this sort of error.
Thanks for working with me on this Neville -
The references were not in the same order but I have now corrected that issue.
[quoted text clipped - 17 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top