Compile Error

bcridez

New member
Local time
Today, 16:00
Joined
Mar 10, 2013
Messages
3
I am trying to run the code below but as soon as I start debugging the following message appears. I have checked and there appear to be no missing references. When the message appears 'cMenu1 As CommandBarControl' is highlighted blue in the code. Does anyone know the problem here? Thanks for any help!

"Compile Error:
User-defined type not defined"

Private Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl
'(1)Delete any existing one.We must useOn Error Resume Next in case it does not exist.
On Error Resume Next
Application.CommandBars("Menu Bar").Controls("Import Tables").Delete
'(2)Set a CommandBar variable to Worksheet menu bar
Set cbMainMenuBar = Application.CommandBars("Menu Bar")
'(3)Return the Index number of the Help menu. We can then use this to place a custom menu before.
iHelpMenu = cbMainMenuBar.Controls("Help").Index
'(4)Add a Control to the "Worksheet Menu Bar" before Help
'Set a CommandBarControl variable to it
Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpMenu)
With cbcCutomMenu
.Caption = "Import Tables"
End With
'(5)Give the control a caption cbcCutomMenu.Caption = "&New Menu"
'(6)Working with our new Control, add a sub control and give it a Caption and tell it which macro to run (OnAction).
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Import Tables"
.OnAction = "ImportTables"
End With
'(6a)Add another sub control give it a Caption and tell it which macro to run (OnAction)
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Delete Tables"
.OnAction = "deletealltables"
End With
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "About"
.OnAction = "OpenAboutUs"
End With
On Error GoTo 0
End Sub
 
Hello and Welcome to AWF.. :)

Are you sure you have all methods? Including Microsoft Office 14.0 Library?

On a side note, when presenting code please use the CODE tags, that would preserve the indentation..
 
Thanks for the quick response. I do not have the 14.0 references there. I deleted them because they were missing. Is there a way I can add the 14.0 reference? I am using Access 2003 so I did not think I needed the 14.0 library.
 
I am using Access 2003 so I did not think I needed the 14.0 library.

Sounds like you are back porting a DB from Access 2010 to Access 2003.

You will need the libraries for Access 2003 in your case. At least the core ones to have enabled in Access 2007 are:

  • Visual Basic for Applications
  • Microsoft Access 12.0 Object Library
  • OLE Automation
  • Microsoft Office 12.0 Access database engine Object
Obviously the versions will be lower with Access 2003, otherwise I believe you should make sure that you have at least those four enabled.


I would also suggest running through this process with a BACKUP of your database file to get other crud cleaned up, especially since you seem to be back porting to a prior version of Access:

NT Command Script and Documented Steps to Decompile / Compact / Compile an Access DB
http://www.access-programmers.co.uk...to_Decompile_/_Compact_/_Compile_an_Access_DB
 
is a commandbarcontrol one of the accdb ribbon controls?

if so, you will not be able to resolve this in A2003
 
FIXED:

I was navigating previously to program files/microsoft office/ and did not find the correct files to fix the problem. I was able to add the reference below and everything is working again.

ReferenceFromFile "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL"
 

Users who are viewing this thread

Back
Top Bottom