From: Keith Wilby on
"Daedalus" <fdprojects(a)hotmail.com> wrote in message
news:4b44b77a$0$395$5f6aeac3(a)news.scarlet.nl...
>
>
>
> I'm using Office (Access) 2003. I suppose I need to include a add-in or so
> ?
> The error I get is on line
> Dim dlgOpen As FileDialog
> and it says (translated from Dutch)
> Compilation error
> A userdefined datatype is not defined
>

This works for me. strTitle contains something like "Select a file." and
strType contains the file extension of the file to be chosen (I believe that
is optional):

Sub GetFile(strTitle As String, strType As String)

Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant

With fd
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add strType & " files", "*." & strType
.Title = strTitle
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strFilePath = vrtSelectedItem
Next vrtSelectedItem
'The user pressed Cancel.
Else
If MsgBox("You did not select a file. Do you want to cancel the
operation?", _
vbYesNo + vbQuestion, "No File Selected") = vbYes Then
Set fd = Nothing
DoCmd.Hourglass False
Me.lblHeader.Caption = "My Title"
strFilePath = "UserAbort"
Exit Sub
Else
'Do something to handle the user cancelling if necessary
End If
End If
End With

End Sub

From: Daedalus on

"Keith Wilby" <here(a)there.com> schreef in bericht
news:4b44bba0$1_1(a)glkas0286.greenlnk.net...
> "Daedalus" <fdprojects(a)hotmail.com> wrote in message
> news:4b44b77a$0$395$5f6aeac3(a)news.scarlet.nl...
>>
>>
>>
>> I'm using Office (Access) 2003. I suppose I need to include a add-in or
>> so ?
>> The error I get is on line
>> Dim dlgOpen As FileDialog
>> and it says (translated from Dutch)
>> Compilation error
>> A userdefined datatype is not defined
>>
>
> This works for me. strTitle contains something like "Select a file." and
> strType contains the file extension of the file to be chosen (I believe
> that is optional):
>
> Sub GetFile(strTitle As String, strType As String)
>
> Dim fd As FileDialog
> Set fd = Application.FileDialog(msoFileDialogFilePicker)
> Dim vrtSelectedItem As Variant
>
> With fd
> .AllowMultiSelect = False
> .Filters.Clear
> .Filters.Add strType & " files", "*." & strType
> .Title = strTitle
> If .Show = -1 Then
> For Each vrtSelectedItem In .SelectedItems
> strFilePath = vrtSelectedItem
> Next vrtSelectedItem
> 'The user pressed Cancel.
> Else
> If MsgBox("You did not select a file. Do you want to cancel the
> operation?", _
> vbYesNo + vbQuestion, "No File Selected") = vbYes Then
> Set fd = Nothing
> DoCmd.Hourglass False
> Me.lblHeader.Caption = "My Title"
> strFilePath = "UserAbort"
> Exit Sub
> Else
> 'Do something to handle the user cancelling if necessary
> End If
> End If
> End With
>
> End Sub
>


Keith

I tried this, but get exactly the same error as soon as entering the sub
'GetFile'
Any idea where that 'FileDialog' is coming from ?
Tanx !

D


From: Keith Wilby on
"Daedalus" <fdprojects(a)hotmail.com> wrote in message
news:4b44be21$0$394$5f6aeac3(a)news.scarlet.nl...
>
>
> I tried this, but get exactly the same error as soon as entering the sub
> 'GetFile'
> Any idea where that 'FileDialog' is coming from ?
> Tanx !
>
>

It might be a missing library reference but I'm not sure which. Try adding
Office 11 Object Library and/or ActiveX Data Objects. I assume you're
calling the sub from the immediate window and supplying the arguments.

Keith.

From: Daedalus on

"Keith Wilby" <here(a)there.com> schreef in bericht
news:4b44c49d$1_1(a)glkas0286.greenlnk.net...
> "Daedalus" <fdprojects(a)hotmail.com> wrote in message
> news:4b44be21$0$394$5f6aeac3(a)news.scarlet.nl...
>>
>>
>> I tried this, but get exactly the same error as soon as entering the sub
>> 'GetFile'
>> Any idea where that 'FileDialog' is coming from ?
>> Tanx !
>>
>>
>
> It might be a missing library reference but I'm not sure which. Try
> adding Office 11 Object Library and/or ActiveX Data Objects. I assume
> you're calling the sub from the immediate window and supplying the
> arguments.
>
> Keith.

Keith



You're the BEST !

I had already the Access 11.0 Object Library included, but it's the Office
11.0 Object Library I needed.

Tanx man !



D


From: David W. Fenton on
"Keith Wilby" <here(a)there.com> wrote in
news:4b44a191_1(a)glkas0286.greenlnk.net:

> Search the help for "FileDialog".

That will be available only if you have a reference to the Office
Automation library. You don't have to have the reference to use the
FileDialog object (though you need it if you want to use the
FileDialog object's data types).

I would recommend not using the FileDialog object, but instead using
the Windows API call, which Pete Cresswell provided code for and
which can also be found here:

http://mvps.org/access/api/api0001.htm

The Windows API file open will work as long as the Win32 API is
supported, whereas MS could decide to remove the FileDialog object
from Access/Office at any time (as it did with the FileSearch object
in Office 2007).

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/