Newbie: Microsoft Office 11.0 Object Library

G

Guest

I'm reviewing the following VBA Reference documentation: FileDialog Property

It gives an example of exactly what I need to do, however, when I type in:
I create a button in my form, and copy the example code:
Private Sub cmdFileDialog_Click()

' Requires reference to Microsoft Office 11.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Clear listbox contents.
Me.FileList.RowSource = ""

' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog

' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True

' Set the title of the dialog box.
.Title = "Please select one or more files"

' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then

'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next

Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub

how ever, when I click the button on my form, it gives me this error:
"Compile error: User-defined type note defined"

Sorry, I'm new to all this VBA stuff, but doesn't Office 2003 install the
Object Library by default? It wouldn't make sense if it doesn't, becuase I'll
eventually have to put this database on a server share for people to use.

Thanks,
Mike (confused)
 
D

Douglas J. Steele

No, the default Access MDB doesn't contain a reference to Office, just to
Access.

Do yourself a huge favour, though: don't use the FileDialog. Instead, use
the API approach illustrated in http://www.mvps.org/access/api/api0001.htm
at "The Access Web". Yes, it's overwhelming code, but you simply have to
copy-and-paste it into your application. In the long run, it's far more
reliable then adding a reference to Office and using the FileDialog object.
 
G

Guest

Not all references libraries are selected by default. But it is fairly
simple to select. Open the Microsoft Visual Basic editor then click on
Tools>References. Scroll down until you find the refence library you want
and make sure the check box is checked.

Please note that sometimes a library can go MISSING: To check this just
follow the steps above and see if the Word MISSING: is next to a library, is
so just uncheck it clise the reference window reopen then recheck it.
 
G

Guest

Please note, I have done this:

MORE INFORMATION
Microsoft Access includes many components. Each component supplies its own
set of objects. The object library of a component contains information about
its objects, its properties, and its methods. These objects are available to
Microsoft Office Access 2003 only if the Access 2003 application contains
references to the corresponding object library.

To view the list of available references for an Access 2003 database
application, follow these steps: 1. Start Microsoft Office Access 2003.
2. Open the Access 2003 database that you want.
3. On the Tools menu that is in the Database window, point to Macro, and
then click Visual Basic Editor.
4. On the Tools menu that is in Visual Basic Editor, click References.

The References - Database Name dialog box appears. The references appear in
the Available References list in this dialog box.

Note The selected library references that appear in the Available References
list are available for use in the current database application.
By default, following references are selected when you create a new
Microsoft Access database in Access 2000 format by using Microsoft Office
Access 2003: • Visual Basic for Applications
• Microsoft Access 11.0 Object Library
• OLE Automation
• Microsoft ActiveX Data Objects 2.1 Library
• Microsoft DAO 3.6 Object Library
By default, following references are selected when you create a new
Microsoft Access database in Access 2002 - 2003 format by using Microsoft
Office Access 2003: • Visual Basic for Applications
• Microsoft Access 11.0 Object Library
• OLE Automation
• Microsoft ActiveX Data Objects 2.5 Library
• Microsoft DAO 3.6 Object Library

as per: http://support.microsoft.com/default.aspx/kb/825796/

but it still gives me the error (everything was set correctly/default)
 
G

Guest

Nevermind, I was having a PEBKAC moment, Office 11.0 Object Lib was not
checked.

Thanks anyways!
 
G

Guest

Thanks Doug! I'm reviewing this code now. :)

Douglas J. Steele said:
No, the default Access MDB doesn't contain a reference to Office, just to
Access.

Do yourself a huge favour, though: don't use the FileDialog. Instead, use
the API approach illustrated in http://www.mvps.org/access/api/api0001.htm
at "The Access Web". Yes, it's overwhelming code, but you simply have to
copy-and-paste it into your application. In the long run, it's far more
reliable then adding a reference to Office and using the FileDialog object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top