Problem with Common File Dialog

J

jfp

In response to a button click on a form, i wish to bring up the standard
"File SaveAs" dialog. In the Click event, i have this code:

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

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

When i try to run it, i get this error on the line above:

Run Time Error -2147467263 (80004001)

The expression you entered refers to an object that is closed or
doesn't exist.

The code is copied from the on-line Microsoft Access VB Reference.
I also tried changing the line in question to:
Set fd = Me.Application.FileDialog(msoFileDialogSaveAs)
but that had no effect.
I have a reference to the "Microsoft Office 10.0 Object Library"
I am running Access XP (2002) under Windows 2000.

What's wrong ?
 
J

jfp

YES -- that is supposed to work (i have not tried) -- but what i am
trying to do would be much easier and SHOULD be possible with Access
2002. IF necessary, i will go back to the approach suggested here --
but i would still like to know what is wrong with what i copied from the
help files.

Perhaps the problem is related to this:
I have Win 2000
It came with Office 2000
I hten added Access 2002 -- but not the rest of Office 2000.
However - the reference to the Office 10.0 Object library is working.

Any ideas ??
-=-=-=-=
 
D

Douglas J. Steele

I don't believe that the FileSave dialog actually works in the control. Yet
another reason why so many of us recommend the API calls instead of using
the control.
 
K

Ken Snell

I don't believe you are to set a FileDialog object. You just need to call
the function and then use the results.

From an earlier post by Joe Fallon (MVP):

This code is a new feature in Access 2002.
It allows you to browse for a file and then store the selected file in 2
text boxes:
Me![txtLocalDir] , Me![txtLocalFileName]

'1 = DialogOpen, 2= SaveAs, 3=FilePicker, 4 = FolderPicker
'Cannot be used in Access 2000!
With Application.FileDialog(3)
.AllowMultiSelect = False
If .Show = True Then
Me![lblEdit].Visible = True
Me![txtLocalDir] = Left$(.SelectedItems(1),
InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName] = Right$(.SelectedItems(1),
Len(.SelectedItems(1)) - InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName].SetFocus
End If
End With
 
J

jfp

Nope -- that fails also.

Clearly, this stuff works -- sometimes.
I get the impression that it is a not very well tested or integrated
feature. Since i will be installing this app on a variety of systems,
it does not sound as though the use of FileDialog would be very
reliable. So -- i guess i write my own based on the API calls. I can
certainly do this (having programmed in C for years with the API) -- i
was assuming (silly me) that the FileDialog stuff would be easier.

BUT -- i would still like to know what might be wrong.
Any more ideas ?

Thanks !
-=-=-=
 
K

Ken Snell

In your references list, is Office 10.0 library a higher priority than
Office 9.0 in the list? If not, move it above the other; it may be that
ACCESS doesn't go to the Office 10.0 library if it finds 9.0 first.

--
Ken Snell
<MS ACCESS MVP>

jfp said:
Nope -- that fails also.

Clearly, this stuff works -- sometimes.
I get the impression that it is a not very well tested or integrated
feature. Since i will be installing this app on a variety of systems,
it does not sound as though the use of FileDialog would be very
reliable. So -- i guess i write my own based on the API calls. I can
certainly do this (having programmed in C for years with the API) -- i
was assuming (silly me) that the FileDialog stuff would be easier.

BUT -- i would still like to know what might be wrong.
Any more ideas ?

Thanks !
-=-=-=
Ken said:
I don't believe you are to set a FileDialog object. You just need to call
the function and then use the results.

From an earlier post by Joe Fallon (MVP):

This code is a new feature in Access 2002.
It allows you to browse for a file and then store the selected file in 2
text boxes:
Me![txtLocalDir] , Me![txtLocalFileName]

'1 = DialogOpen, 2= SaveAs, 3=FilePicker, 4 = FolderPicker
'Cannot be used in Access 2000!
With Application.FileDialog(3)
.AllowMultiSelect = False
If .Show = True Then
Me![lblEdit].Visible = True
Me![txtLocalDir] = Left$(.SelectedItems(1),
InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName] = Right$(.SelectedItems(1),
Len(.SelectedItems(1)) - InStrRev(.SelectedItems(1), "\"))
Me![txtLocalFileName].SetFocus
End If
End With
 
J

jfp

There was NO reference to any previous Office ## when i added ref to
Ofice 10.0 Just to be sure, i moved it as high as possible -- 3rd on
list, underneath only VBA and Access 10.0
There was NO change.

Do you have any comments on Doug Steele's observation ?
-=-=
 
K

Ken Snell

No. Sorry.

--
Ken Snell
<MS ACCESS MVP>

jfp said:
There was NO reference to any previous Office ## when i added ref to
Ofice 10.0 Just to be sure, i moved it as high as possible -- 3rd on
list, underneath only VBA and Access 10.0
There was NO change.

Do you have any comments on Doug Steele's observation ?
-=-=
 

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

Similar Threads

problem with file dialog 2
FilePicker dialog box in 2002 3
FileDialog Filters.clear 1
FileDialog 1
mso.dll for filedialog 2
PresentationBeforeSave 6
File Dialog 6
FileDialog Widget 2

Top