Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

open windows file dialog

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Open Windows File dialog box using VBA?

Open Windows File dialog box using VBA?

ResolvedVersion 2003
Edited on Fri 16 Apr 2010, 13:43

Joanne has attended:
Access VBA course

Open Windows File dialog box using VBA?

Hi I would like to able to open the Windows File Dialog via a command button. Simular as a Browse Files Button. A lot of the samples I have seen open up chosen files but I would like the user to open the C:\Drive and Browse for their File. And also for that path to be pasted into a field? Is this possible?
Jo

RE: Open Windows File dialog box using VBA?

Hi Joanne

I had exactly the same issues a couple of weeks ago. The code I used is:

Private Sub Attach_Click()

Dim varItem As Variant
Dim strPath As String
Dim filePicker As FileDialog

Set filePicker = Application.FileDialog(msoFileDialogFilePicker)

With filePicker

'setup File Dialog'
.AllowMultiSelect = False
.ButtonName = "Select"
.InitialView = msoFileDialogViewList
.Title = "Select File"
.InitialFileName = "G:\z- 2010 General\Information Systems"

'add filter for all files'
With .Filters
.Clear
.Add "All Files", "*.*"
End With
.FilterIndex = 1

'display file dialog box'
.Show

End With

If filePicker.SelectedItems.Count > 0 Then

Dim selectedFile As String
selectedFile = filePicker.SelectedItems(1)

Me.PathToFile = selectedFile

End If

End Sub

Hope this helps!

David

RE: Open Windows File dialog box using VBA?

Hey David thanks for your help.
Jo

RE: Open Windows File dialog box using VBA?

I should also add that the

.InitialFileName = "G:\z- 2010 General\Information Systems"

is where you set your C:\Drive

and the

Me.PathToFile = selectedFile

is where the chosen file location is put into the form/field.

David

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Access tip:

Random sampling

Data is th key to a good database, therefore checking is essential.

A good way of checking data is by random sampling. You can do this in a query, by typing the follow:
1) In the Field box create a RandonID field eg. Randon Id: Rnd(fieldname])

2) sort the field
3)Right click and chage the properties for To value to be the number of randon records you want to see.

4) Change the set to Show row for Randon ID to be False, add all the other fields you want to see and the run the query.

View all Access hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.