p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning Access 2003 VBA (http://p2p.wrox.com/forumdisplay.php?f=150)
-   -   chapter 10 problem (http://p2p.wrox.com/showthread.php?t=40727)

nikItas April 3rd, 2006 02:48 PM

chapter 10 problem
 
In chapter 10 I try to create the command bar and everything in code seems fine but when I run it I get the error message: run time error 5, invalid procedure call or argument. I have also added the office 11 object library. Can someone suggest a solution?

Sub CreateCommandBar()

Dim cbReport As CommandBar
Dim btnButton As CommandBarButton

'delete the command bar and if it does not exist, continue
On Error Resume Next
CommandBars("Wrox1 Report").Delete

On Error GoTo 0

'add the new command bar to the collection
Set cbReport = CommandBars.Add("Wrox1 Report", msoBarFloating)

'add Zoom button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
    CommandBars("Print Preview") _
    .Controls("Zoom").Id)

'add 2 pages button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
    CommandBars("Print Preview") _
    .Controls("Two Pages").Id)

'add copy button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton, _
    CommandBars("Database") _
    .Controls("Copy").Id)

'add a custom button to the toolbar
Set btnButton = cbReport.Controls.Add(msoControlButton)
btnButton.Caption = "Test Button"
btnButton.Style = msoButtonCaption
'list the name of the procedure to call when the button is clicked
btnButton.OnAction = "DisplayMessage"

'display the new command bar by setting visible
cbReport.Visible = True

End Sub

Sub DisplayMessage()

MsgBox "The new button was clicked."

End Sub

mikkelB August 5th, 2008 08:54 AM

I have the same error here (using the code downloaded from wrox.com), anyone got any ideas?



All times are GMT -4. The time now is 10:00 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.