Allow User to Select Path of Import File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a need to import a text file into Access but want to give the user the
flexibility of selecting the path where the file is being imported from. At
the moment I've tested with a fixed path in the code and the import works
fine, but this is being more restrictive than I want to be. I'd appreciate
any help in how to achieve this.

Thanks, Dave
 
Try this
Sub GetFile(Control)
Dim retFile As String, dlg As Variant, s As String
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.InitialFileName = CodeProject.Path
If .Show = -1 Then s = .SelectedItems(1)
End With
If s <> "" Then
retFile = Right(s, Len(s) - InStrRev(s, "\"))
Control.Value = retFile
End If
End Sub

HTH;

Amy
 
If you'd like to see a small Access database sample based on the link that
John provided, I've got one on my website: (www.rogersaccesslibrary.com).
It is called "PictureLoad.mdb". This does not choose a file for importing,
rather choosing a picture for adding to the database, but the methodology is
the same. The only difference is what you choose to do with the selected
file.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Back
Top