In later versions of Access you can use the FileDialog property of the Application object.
Here is an extract from the MSAccess help file:
Using the FileDialog object
Use the FileDialog property to return a FileDialog object. The FileDialog property is located in each individual Office application's Application object. The property takes a single argument, DialogType, that determines the type of FileDialog object that the property returns. There are four types of FileDialog object:
Open dialog box - lets users select one or more files that you can then open in the host application using the Execute method.
SaveAs dialog box - lets users select a single file that you can then save the current file as using the Execute method.
File Picker dialog box - lets users select one or more files. The file paths that the user selects are captured in the FileDialogSelectedItems collection.
Folder Picker dialog box - lets users select a path. The path that the user selects is captured in the FileDialogSelectedItems collection.
Each host application can only instantiate a single instance of the FileDialog object. Therefore, many of the properties of the FileDialog object persist even when you create multiple FileDialog objects. Therefore, make sure that you've set all of the properties appropriately for your purpose before you display the dialog box.
In order to display a file dialog box using the FileDialog object, you must use the Show method. Once a dialog box is displayed, no code will execute until the user dismisses the dialog box. The following example creates and displays a File Picker dialog box and then displays each selected file in a message box.
Sub Main()
Dim fd As FileDialog 'Declare a variable as a FileDialog object
Set fd = Application.FileDialog(mso
'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
With fd 'Use a With...End With block to reference the FileDialog object to loop thru multiple files.
'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
'vrtSelectedItem is a String that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this 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
Main Topics
Browse All Topics





by: rockmuncherPosted on 2004-06-28 at 19:34:40ID: 11422304
In ACC97 you would use the Common Dialog Controls library (which you need to reference using Tools - References from a code window).
1.FileName & ""
1.FileName & ""
library/en -us/vbcon9 8/html/ vbc ondisplayi ngopensave asdialogbo xes.asp?fr ame=true
Here's an example from the Microsoft MSDN site:
Private Sub mnuFileOpen_Click ()
Dim strFileToOpen as variant
' CancelError is True.
On Error GoTo ErrHandler
' Set filters.
CommonDialog1.Filter = "All Files (*.*)|*.*|Text _
Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CommonDialog1.FilterIndex = 2
' Display the Open dialog box. User makes selection
CommonDialog1.ShowOpen
strFileToOpen=CommonDialog
'<PUT CODE TO OPEN AND IMPORT HERE>'
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
The user selection is stored in the FileName property of the CommonDialog1 control on a form. To reference it you simply use strFileToOpen=CommonDialog
For more info see the article on MSDN at http://msdn.microsoft.com/