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 (http://p2p.wrox.com/showthread.php?t=34259)

gogeo October 13th, 2005 06:27 PM

Chapter 10
 
Is anyone having problems with adding the new CommandBar in Chapter 10 this is what I have and it comes back with "method or data not found" and the Style:
 Option Compare Database
Option Explicit

Sub CreateCommandBar()
Dim cbReport As CommandBar
Dim btnButton As CommandButton

'delete the command Bar and if it does not exist, continue
On Error Resume Next
CommandBars("Wrox Report").Delete
On Error GoTo 0

'add the new command bar to the collection
Set cbReport = CommandBars.Add("Wrox 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 customer 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.OnClick = "DisplayMessage"

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

End Sub

Sub DisplayMessage()

MsgBox "The new button was clicked"

End Sub
 Could someone help me!


Damien January 22nd, 2006 09:41 AM

Denise got it right from what I can see - You've just doena couple of Typos !

a)
You have at the top : Dim btnButton As CommandButton

You should have : Dim btnButton As CommandBarButton

b)
You have towards the end :
btnButton.OnClick = "DisplayMessage"
You Should have :
btnButton.OnAction = "DisplayMessage"

c)
You may also need to make a reference to Microsoft Office 10.0 - or 11.0 or whatever you have in the Tools references - I've seen some Access set ups that don't have this ticked automatically

Hope this helps
Damien




All times are GMT -4. The time now is 05:57 PM.

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