FileDialog object (1 Viewer)

trackdaychamp

Access Guy
Local time
Today, 04:11
Joined
Jan 22, 2007
Messages
26
Hi,

I have inherited some code from an MDB but need to migrate it to and ADP format.

Does anyone know the correct syntax for a File Dialog object in ADP. I am getting the following error for the code below "User defined type not defined"

:confused:

'Declare a variable as a FileDialog object.
Dim fd As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFolderPicker)

'Declare a variable to contain the path
'of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

'Use a With...End With block to reference the FileDialog object.
With fd

'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then

'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems

Me![txtFolderPath] = vrtSelectedItem

Next vrtSelectedItem

End If

End With

'Set the object variable to Nothing.
Set fd = Nothing
 

MarkK

bit cruncher
Local time
Yesterday, 20:11
Joined
Mar 17, 2004
Messages
8,181
I believe the FileDialog Class is provided by the Office object model, so you have two options. Late-bind the object by changing your variable declaration from ...
Code:
Dim fd As FileDialog
 - to -
Dim fd As Object
Or, early-bind. in a VBA window, navigate to Menu->Tools->References, and set a reference to Microsoft Office XX, where XX is the version number.

Late-binding is a little slower, but much safer if your users have varying versions of office products. Early binding is quicker, offers you intellisense during development, but if your users don't have the same or later version of Office, the reference is either broken or missing when the DB opens and you hvae an ugly crash and burn situation.

Also, earlier versions of the Access.Application object do not expose a FileDialog Object, so even if you late-bind you'll have a problem there.

One other issue if you late bind is that enumeration members, like 'msoFileDialogFolderPicker' will need to be replaced with the values they represent or declared within your app as constants like
Code:
Public Const msoFileDialogFolderPicker = <value>
Hope this helps,
 

Users who are viewing this thread

Top Bottom