Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / August 2005

Tip: Looking for answers? Try searching our database.

Open a datasheet from Switchboard

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kateyliz - 26 Jul 2005 15:38 GMT
Does anyone know if it is possible to open up a datasheet from the
Switchboard?  I seem only to be able to create buttons for forms on the
switchboard...

Many thanks

Katie
Brian - 26 Jul 2005 16:00 GMT
You could just open the form in datasheet view (DoCmd.OpenForm "FormName",
acFormDS)

> Does anyone know if it is possible to open up a datasheet from the
> Switchboard?  I seem only to be able to create buttons for forms on the
[quoted text clipped - 3 lines]
>
> Katie
Jeff Conrad - 26 Jul 2005 18:56 GMT
See this page on my site for any and all SBM questions:

http://home.bendbroadband.com/conradsystems/accessjunkie/switchboardfaq.html

In your particular case, this spot:

http://home.bendbroadband.com/conradsystems/accessjunkie/switchboardfaq.html#dat
asheet


(Watch out for any line wrapping on the links)

Signature

Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

> Does anyone know if it is possible to open up a datasheet from the
> Switchboard?  I seem only to be able to create buttons for forms on the
> switchboard...
kateyliz - 27 Jul 2005 09:59 GMT
Thank you for this information - please can you tell me how I can view the
"commands" for the switchboard?  I can't seem to be able to find them

> See this page on my site for any and all SBM questions:
>
[quoted text clipped - 9 lines]
> > Switchboard?  I seem only to be able to create buttons for forms on the
> > switchboard...
Jeff Conrad - 27 Jul 2005 21:08 GMT
If you open the Switchboard form in Design View and then go
to the code window you will see these command constants
assigned in the HandleButtonClick function:

   ' 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

Signature

Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

> Thank you for this information - please can you tell me how I can view the
> "commands" for the switchboard?  I can't seem to be able to find them
[quoted text clipped - 8 lines]
> >
> > (Watch out for any line wrapping on the links)
kateyliz - 28 Jul 2005 09:49 GMT
Thank you for this.  I have now managed to find the command.  However, there
appears to be an error executing the command.

I have 9 lines already in my code, so I put yours as "10":

   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
   Const conCmdOpenFormDatasheet = 10

Also I had some extra code in between at the bottom so I have added mine to
it:

' Run code.
       Case conCmdRunCode
           Application.Run rs![Argument]
       
       ' Open a Data Access Page
       Case conCmdOpenPage
           DoCmd.OpenDataAccessPage rs![Argument]
           
       ' Open a form in Datasheet Mode.
       Case conCmdOpenFormDatasheet
           DoCmd.OpenForm rst![Argument], acFormDS

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

Are these extra lines of code what are causing my problems?

I also tried entering some code as a seperate function (as per your website)
but that was causing an error too...

Public Function OpenMyForm(Project_List)

DoCmd.OpenForm "frmProject_List", acFormDS

End Function

Sorry to sound so dense... I am not au fait with all this programming, so
can't see where there may be problems.

Your help is very much appreciated!!

> Thank you for this information - please can you tell me how I can view the
> "commands" for the switchboard?  I can't seem to be able to find them
[quoted text clipped - 12 lines]
> > > Switchboard?  I seem only to be able to create buttons for forms on the
> > > switchboard...
Jeff Conrad - 28 Jul 2005 16:51 GMT
Comments inline....

> Thank you for this.  I have now managed to find the command.  However, there
> appears to be an error executing the command.

What exactly is the error message you are receiving?

> I have 9 lines already in my code, so I put yours as "10":
>
[quoted text clipped - 8 lines]
>     Const conCmdOpenPage = 9
>     Const conCmdOpenFormDatasheet = 10

That all looks just fine.

> Also I had some extra code in between at the bottom so I have added mine to
> it:
[quoted text clipped - 16 lines]
>
> Are these extra lines of code what are causing my problems?

That all looks pretty good except for one thing.

In the Datasheet one you have the recordset as "rst" and in the
other ones listed you use only "rs" as the recordset. Is it defined
as rs or rst in your Declarations?

> I also tried entering some code as a seperate function (as per your website)
> but that was causing an error too...
[quoted text clipped - 4 lines]
>
> End Function

What was the error message?

Try changing that to this:

Public Function OpenMyForm()

DoCmd.OpenForm "frmProject_List", acFormDS

End Function

Run the SBM and select RunCode and then enter
OpenMyForm on the Function Name line.

> Sorry to sound so dense... I am not au fait with all this programming, so
> can't see where there may be problems.

Don't worry you are not dense.
What version of Access are you using by the way?

> Your help is very much appreciated!!

No problem, we'll figure it out.

Signature

Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

kateyliz - 05 Aug 2005 14:36 GMT
Hi Jeff

Error message when using module "OpenMyForm" is The was an error executing
this command".  I copied and pasted your new suggestion in but am still
getting the same problem.

The other method you have suggested - have removed the "!" from the code and
the sheet now opens without errors but still as a form view rather than
datasheet view!

I am using Access 2003

Thanks again for your help

> Comments inline....
>
[quoted text clipped - 76 lines]
>
> No problem, we'll figure it out.
Jeff Conrad - 05 Aug 2005 18:47 GMT
> Error message when using module "OpenMyForm" is The was an error executing
> this command".  I copied and pasted your new suggestion in but am still
> getting the same problem.

Please post the code you have in the module now as well as *exactly* what
you put in the RunCode option in the Switchboard Manager.

> The other method you have suggested - have removed the "!" from the code and
> the sheet now opens without errors but still as a form view rather than
> datasheet view!

I did not suggest removing the "!" (exclamation mark) at all!
I noted your recordset was rs in some places and rst (note the letter t
at the end) in another place. Those need to match your declaration.

Please post the modified code you have currently.

> I am using Access 2003

Ok, sounds fine.

> Thanks again for your help

No problem.
Signature

Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

kateyliz - 16 Aug 2005 12:31 GMT
Hi Jeff

Sorry I misunderstood and thought you meant take the ! off.

This is all the code for the switchboard

Option Compare Database

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
   Const conCmdOpenFormDatasheet = 10
 
   ' 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]
       
       ' Open a form in Datasheet Mode.
       Case conCmdOpenFormDatasheet
           DoCmd.OpenForm rs![Argument], acFormDS
     
       ' 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

Please can you tell me how to find out what I am using for my declaration?

Thanks

Katie

> > Error message when using module "OpenMyForm" is The was an error executing
> > this command".  I copied and pasted your new suggestion in but am still
[quoted text clipped - 20 lines]
>
> No problem.
Jeff Conrad - 23 Aug 2005 06:10 GMT
Sorry for the delay, I was on vacation.
Try using this code for the HandleButtonClick function:
Works just fine for me.
I used 10 in the command field of the table to open a form in datasheet.

' Code Start
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
   Const conCmdOpenFormDatasheet = 10

   ' 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]

       ' Open a form in Datasheet Mode.
       Case conCmdOpenFormDatasheet
           DoCmd.OpenForm rs![Argument], acFormDS

       ' 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
' Code End

Signature

Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

> Hi Jeff
>
> Sorry I misunderstood and thought you meant take the ! off.
>
> This is all the code for the switchboard

<<code snipped>>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.