PDA

View Full Version : Wont the fileopendialog.execute method work in Access?



prabhafriend
12-08-2010, 04:02 AM
Won't the fileopendialog.execute method work in Access? What's the alternative then?

SoftwareMatt
12-08-2010, 05:31 AM
This might help you:
http://visualbasic.ittoolbox.com/documents/file-open-dialog-in-access-12139

prabhafriend
12-08-2010, 05:58 AM
No Matt. There aren't using the execute method there.

orange
12-08-2010, 12:17 PM
Go to Tools > References dialog in the VBA environment and make sure to find and check the entry for

"Microsoft Office.. Object Library"

Also look in Object Browser to see what Methods are available, could try Google also.

Here is a M$oft link
http://msdn.microsoft.com/en-us/library/aa195878%28office.11%29.aspx
Here is some sample code I found via Google.

Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)

With dlgOpen
.AllowMultiSelect = False
.Show
End With

prabhafriend
12-08-2010, 11:27 PM
What happened guys? Why aren't you going through links before posting it. There is no execute in the link orange referred also. Please somebody confirm whether the execute does work in access or not? Please confirm

orange
12-09-2010, 11:46 AM
Did you use the Object Browser and look for methods? Did you try Google?



Here's some more info - found via Google -http://support.microsoft.com/kb/288543

To use a FileDialog object, you must first call the FileDialog property of an Office XP Application object and provide an argument for the DialogType. There are four types of file dialogs:
Open Dialog (msoFileDialogOpen) - allows users to select one or more files. If you choose to do so, you can then open the selected file or files in the host application by using the Execute method.
SaveAs Dialog (msoFileDialogSaveAs) - allows users to select a single file. If you choose to do so, you can then save the current file by using the Execute method.
File Picker Dialog (msoFileDialogFilePicker) - allows users to select one or more files. The file paths that the user selects are captured in the FileDialogSelectedItems collection.
Folder Picker Dialog (msoFileDialogFolderPicker) - allows users to select a folder. The path for the selected folder is captured in the FileDialogSelectedItems collection.Each host Office application can only instantiate a single instance of a FileDialog object. Many of the properties of the FileDialog object persist even when you create multiple FileDialog objects. Therefore, you should initialize all of the dialog properties appropriately for your purpose before you display the dialog box.

Once you have a reference to a FileDialog object, you can display the dialog box by using the Show method. All FileDialog objects are modal so once a dialog box is displayed, no code continues to execute until the dialog box is dismissed. Your code can also check the return value of the Show method to determine if the user accepts or cancels the file (or folder) selection and then to handle that condition as needed.

The following sample VBA code creates and shows a File Picker dialog box. When you run the code to display the dialog box, select one or more files and click OK to dismiss the dialog box. Each of your file selections is displayed in a message box. Note that you can use the CTRL+SHIFT keyboard combination in the dialog box to select multiple files. Sub Main()

'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(msoFileDialogFilePicker)

'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
'The user pressed the action button.
If .Show = -1 Then

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

'vrtSelectedItem contains the path of each selected item.
'Here use any file I/O functions you want on the path.
'This example simply displays the path in a message box.
MsgBox "The path is: " & vrtSelectedItem

Next vrtSelectedItem
'The user pressed Cancel.
Else
End If
End With

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

End Sub


After you call the Show method to display a file dialog box, if the dialog box is type msoFileDialogOpen or msoFileDialogSaveAs, you can call the Execute method to carry out the default Open or Save action. For example, if the file dialog box type is msoFileDialogOpen, you can call the Execute method to open the file selected by the user.

prabhafriend
12-10-2010, 01:41 AM
Sub test()
Dim mydiag As FileDialog
Set mydiag = Application.FileDialog(msoFileDialogOpen)
With mydiag
.Show
.Execute
End With
End Sub
The above gives the following error:
Run-time error '-214767259
You already have the database open.

PS:
Microsoft Office 10.0 Object Library is refered.

If you think that I haven't tried it before asking. Kindly copy and paste the code and see the error. Any way I'm trying it it Office XP.

orange
12-10-2010, 06:31 AM
I tried your code and got the same error. I tried modifying some of my code to use the Execute method (which I don't really understand) but it failed as well.

I did some more detailed searching and found a response by Allen Browne ( for whom I have much respect) to a similar question.
(site is http://bytes.com/topic/access/answers/201953-open-file-folder-dialog)

Here is the essence of his response
"The reference at:
http://www.mvps.org/access/api/api0002.htm
has recently been updated so it does allow a starting folder.

If you don't like the API calls, there is a FileDialog object in Access 2002
and 2003, but it's not very good. It requires an extra library reference,
does not work for Save As (even though it appears to offer that choice), and does not work at all in the runtime."

I could not find an example of the FileDialog.Execute, but I'm not sure what it is suppose to do. I had used the FilePicker in code, but not the .execute method. The option is definitely available, but I could not get it to work.


You might try the API that Allen mentioned if it applies.

prabhafriend
12-10-2010, 07:15 AM
I sincerely thanks your efforts Orange. Thank you.

hansup
12-10-2010, 10:09 AM
If you describe what you hope to accomplish with FileDialog.Execute, perhaps we can suggest an alternative method to achieve your goal.

prabhafriend
12-13-2010, 02:18 AM
.Execute will execute the action of the dialogbox (in this case Opening action)

hansup
12-13-2010, 08:18 AM
You can get the path to the target file from the FileDialog, then use Application.FollowHyperlink to open the file.

Sub test()
Dim fd As Object

Set fd = Application.FileDialog(1) 'msoFileDialogOpen
With fd
If .Show = -1 Then
Application.FollowHyperlink .SelectedItems.Item(1)
End If
End With
Set fd = Nothing
End Sub

prabhafriend
12-13-2010, 08:25 AM
That's a new one. FollowHyperlink. Thank Hansup.