Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3
This is the forum to discuss the Wrox book Access 2007 VBA Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Armen Stein; ISBN: 9780470047033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 15th, 2011, 03:40 PM
Registered User
 
Join Date: Apr 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default CallBacks for Ribbon

I reviewed the customize ribbon chapter and have have built a nice custom ribbon for my application. I am however having a problem with a dropdown box. I used the example chapter files to put in my database to try out.
The drop down box comes up on the ribbon and I use the basRibbonCallbacks module just like the example program from the book. every thing is pretty much the same in my program as the example program except I changed the table and field names to match my database.
the problem is when i open the database a message appears that access can't run the macro or callback "OnGetItemCallback" to find the Count for the dropdown box.
I have looked over the example ribbon XML file and my XML file and the example module and my module and i cant find any differences, everything is spelled exactly the same.
If any of that makes any sense to you, my question is: Are there any setting I need to look at so my ribbon file will call the module, or am i missing something else (i know its hard to say without looking at the database).
Like I said I copied the syntax of the example and added it to my database and it doesnt work.
Reply With Quote
  #2 (permalink)  
Old April 16th, 2011, 11:54 AM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Make sure the VBA code is in a Public function

Hello algiersnola,

Thank you for the note and for reviewing our book, I hope it has been useful to you!

So, to follow up on your question: is your "OnGetItemCallback" function marked as "Public"? It sounds to me (from the error message you described) that the function cannot be found due to its code access level. So please make sure that the function is in a Public Module and that the function is marked as Public.

Anyway, hopefully this helps, but if you have other questions, please let me know!
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
  #3 (permalink)  
Old April 16th, 2011, 01:06 PM
Registered User
 
Join Date: Apr 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. yes the function is public. I'm not sure about the module, I just selected add module from the menu and put the code in it, I assume its public. as far as the code is concerned, I just copied exactly how it was in the example code and just changed the id, table, field names to match mine.
Reply With Quote
  #4 (permalink)  
Old April 17th, 2011, 05:15 PM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Reference to Microsoft Office 12.0 Object Library?

Hello algiersnola,

Thank you for the follow up note here. Hmm, I'm wondering if you added a reference to the "Microsoft Office 12.0 Object Library" in you database application file? If not, you'll have to do that...but otherwise, I would guess there is a problem with the XML code for your Ribbon. So, if you do already have a reference set to the "Microsoft Office 12.0 Object Library", then please post the specific RibbonXML you are using and I'll take a look!

Thanks,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
  #5 (permalink)  
Old April 17th, 2011, 05:44 PM
Registered User
 
Join Date: Apr 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i checked the reference and it is checked. Here is my XML code for the ribbon. every thing works good except the dropdown section near the bottom. I also pasted the basRibbonCallbacks module after the XML code.

XML code

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon startFromScratch="true">
  
  <officeMenu>
  <button idMso="FileOpenDatabase" visible="false"/>
  <button idMso="FileNewDatabase" visible="false"/>
  <splitButton idMso="FileSaveAsMenuAccess" visible="false"/>
  </officeMenu>
    <tabs>
    <tab id="tabMain" label="Express Energy Services">

    <group id="grpWireline" label="Wireline">
   <button id="cmdRuns" label="Enter Wireline Runs" onAction="Ribbon.Run Input" imageMso="OpenStartPage" size="large" supertip="Opens the wireline run input form"/>
    <button id="cmdChargeBacks" label="Wireline Charge Back" onAction="Ribbon.Charge Back" imageMso="CreateReport" supertip="Opens Charge back form"/>
    <button id="cmdExplosiveLicense" label="Explosive Licenses" onAction="Ribbon.Explosive License" imageMso="CreateReport" supertip="Opens current explosive license holders"/>
    <button id="cmdExplosiveUsage" label="Explosive Usage" onAction="Ribbon.Explosive Usage" imageMso="CreateReport" supertip="Opens explosive usage form"/>
         </group>

         <group id="grpRentals" label="Rentals">
         <button id="cmdRentalsTracking" label="Track Rentals" onAction="Ribbon.Rental Tracking" imageMso="ReviewAcceptChange" size="large" supertip="Enter daily rental charges"/>
         <button id="cmdRentalSheet" label="All current rentals" onAction="Ribbon.Current Rentals" imageMso="CreateReport" supertip="Show all rentals for all jobs"/>
         <button id="cmdAddRental" label="Add new rental" onAction="Ribbon.Rental Input" imageMso="ViewsFormView" supertip="Add a new rental for a job"/>
         </group>

	<group id="grpJob" label="Job Info">
	<button id="cmdJob" label="View Jobs" onAction="Ribbon.Job" imageMso="ViewsFormView"
size="large" supertip="View Job Information"/>
	</group>
	
	<group id="grpPersonnel" label="Personnel">
	<button id="cmdPersonnel" label="View Personnel" onAction="Ribbon.Personnel"
imageMso="AccessTableContacts" size="large" supertip="View personnel information"/>
	</group>
         
         <group id="grpMSDS" label="MSDS">
         <button id="cmdFindMsds" label="MSDS Look Up" onAction="Ribbon.MsdsLookup" size="large" imageMso="ViewsFormView" supertip="Find an MSDS"/>
         </group>

	<group id="grpMaintenance" label="Maintenance">
	<menu id="mnuMaintenance" label="Maintenance" size="large" imageMso="PageMenu">
	<menuSeparator id="msMaint" title="Navigation Pane"/>
	<button id="cmdOpen" label="Open Pane" onAction="Ribbon.MaintenanceOpen" imageMso="ShapeRightArrow" supertip="Open navigation pane"/>
	<button id="cmdClose" label="Close Pane" onAction="Ribbon.MaintenanceClose" imageMso="ShapeLeftArrow" supertip="Closes navigation pane"/>
	<menuSeparator id="msComp" title="Compact and Repair"/>
	<button idMso="FileCompactAndRepairDatabase" />
	<button idMso="FileBackupDatabase"/>
	<button idMso="VisualBasic"/>
	</menu>
	</group>

	<group id="grpJobs" label="Job">
	<dropDown id="ddnJob" label="Current Jobs"
		getItemCount="OnGetItemCount"
		getItemLabel="OnGetItemLabel"
		getItemID="OnGetItemID"
		onAction="OnselectItem" >
	</dropDown>
	</group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
basRibbonCallbacks module code

Code:
Option Compare Database

Option Explicit

Dim rst As DAO.Recordset


Public Sub OnGetItemCount(ctl As IRibbonControl, ByRef Count)
    ' return the number of items
    If ctl.ID = "ddnJob" Then
        ' open the Recordset and return the count
       Set rst = CurrentDb.OpenRecordset("Job")
        Count = rst.RecordCount
    End If

End Sub

Public Sub OnGetItemLabel(ctl As IRibbonControl, index As Integer, ByRef Label)
    If ctl.ID = "ddnJob" Then
        If Not rst.EOF Then
            ' set the label text
            Label = rst("Job_Company") & " " & rst("Job_Field")
        End If
    End If
End Sub

Public Sub OnGetItemID(ctl As IRibbonControl, index As Integer, ByRef ID)
    If ctl.ID = "ddnJob" Then
        ' make sure we are not at EOF
        If Not rst.EOF Then
            ' set the id using the ID field in the table
            ID = "Job_ID" & rst("ID")
            
            ' get the next employee
            rst.MoveNext
            
            ' cleanup when we are at EOF
            If rst.EOF Then
                rst.Close
                Set rst = Nothing
            End If
        End If
    End If
End Sub

Public Sub OnSelectItem(ctl As IRibbonControl, selectedId As String, selectedIndex As Integer)
    Dim lngID        As Long
    Dim strCompany As String
    Dim strField  As String
    
    ' parse the ID from the ID string
    lngID = CLng(Replace(selectedId, "Job_ID", ""))
    
    ' get the first and last name
    strCompany = DLookup("Job_Company", "Job", "ID = " & lngID)
    strField = DLookup("Job_field", "Job", "ID = " & lngID)
    
    MsgBox "Welcome, " & strCompany & " " & strField
End Sub
Reply With Quote
  #6 (permalink)  
Old April 18th, 2011, 12:56 AM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Your Ribbon code works for me!

Hello algiersnola,

Thanks for following up here and sending this code over to me. I tried to duplicate your problem using your Ribbon XML and VBA code in a brand new Access 2007 database, but it seems to be working just fine for me!!

So, once again, please make sure that you have a reference to the "Microsoft Office 12.0 Object Library" (so that you have at least 5 references in your database application). Also, please make sure that you have the database application enabled so that your VBA code will run.

For example, if I remove the Microsoft Office 12.0 Object Library reference from my VBA project, then close and reopen the database and enable code for the database, I get an error message that says:

Quote:
Microsoft Office Access can't run the macro or callback function 'OnGetItemCount'.
Make sure the macro or function exists and takes the correct parameters.
Is this the error message that you are seeing? Otherwise, like I said, your Ribbon XML and VBA callback code seem to be working from what I can tell!

Anyway, if there is anything else I can do to help, please let me know!

Thanks,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
  #7 (permalink)  
Old April 18th, 2011, 09:39 AM
Registered User
 
Join Date: Apr 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default references

I double checked and here are the 4 references that are checked.

Visual Basic for Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Access Database Engine Object Library

Thanks for your time on this, it has to be something simple I am missing.
Reply With Quote
  #8 (permalink)  
Old April 18th, 2011, 11:55 AM
Registered User
 
Join Date: Apr 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default working

Ok, my bad, my brain was not working. My brain wasn't distinguishing between Office object library and Access object library. I clicked Office object library and it now see's the procedure. I just have to fix some bugs now to get it working.

thanks again for all of your help.
Scott
Reply With Quote
  #9 (permalink)  
Old April 18th, 2011, 03:23 PM
gjgriffith's Avatar
Wrox Author
Points: 517, Level: 8
Points: 517, Level: 8 Points: 517, Level: 8 Points: 517, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: Boulder, CO
Posts: 110
Thanks: 5
Thanked 14 Times in 14 Posts
Default Glad to hear you got it working!

Hello Scott,

I'm really glad to hear that you were able to get your custom Ribbon code working. Also, I'm extremely pleased to hear that you have been reading the Access 2007 VBA Programmer's Reference and that it has been helping you build your custom Ribbon! We really appreciate you reading the book and if there is anything else I can do to help, please just let me know!

Sincerely,
__________________
Geoffrey L. Griffith
http://www.ImagineThought.com

Wrox Author of:
Microsoft Access 2010 24-Hour Trainer
Access 2010 Programmer's Reference
Access 2007 VBA Programmer's Reference

*** Please click the THANKS button (to the right) if this post helped you! *** ---------------------------------------------------------------------------------------------------------->
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4: Example Ribbon Customization phlegyas BOOK: Professional SharePoint 2010 Development 1 October 29th, 2010 06:37 AM
Custom Office ribbon ayazhoda Access VBA 0 May 29th, 2008 09:36 AM
Access 2007 won't let me select a ribbon bgnetman Access 0 October 23rd, 2007 12:04 PM
Access 2007 Ribbon button link to .chm aholley0628 Access 0 September 13th, 2007 02:35 PM



All times are GMT -4. The time now is 12:19 AM.


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