open windows file dialog
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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?

resolvedResolved · High Priority · Version 2003

replyReply Fri 16 Apr 2010, 13:42 Edited on Fri 16 Apr 2010, 13:43Delegate Joanne said...

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

For upcoming training course dates see: Pricing & availability

replyReply Tue 20 Apr 2010, 11:09Delegate David said...

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

replyReply Tue 20 Apr 2010, 11:31Delegate Joanne said...

RE: Open Windows File dialog box using VBA?

Hey David thanks for your help.
Jo

replyReply Tue 20 Apr 2010, 11:11Delegate David said...

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

 

Please browse our web site to find out more about
2003 access micorosft training and other Microsoft training courses.

Access tip:

Relationship maps

It is important to create proper relationships between tables. You can use Access to help check your designs and evaluate them by printing them in graphical format to help with design purposes


Click on the Tools menu, click Relationships.
On the File menu, click Print Relationships. View or print as required

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard