Access Help

dysfunction

FH is my second home
Joined
Dec 22, 2003
Messages
9,709
I need some help with MS Access.
What I would like to do is click a button and the file dialog will open up so that I can select a file to import into the Access Database. The file location will then be displayed in a box.

I have the following code which works perfectly but I would like the file location to be fixed. At the moment it is fixed to the last selected loaction but I need it to be fixed to say C:\ only.

How can I do this?

Code:
Dim dlgopen As FileDialog
'Declare a variable to contain the path
Dim spath As Variant



' Set up the File Dialog.
Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)
    
With sMyPath

      ' Allow users to not make multiple selections in dialog box
      .AllowMultiSelect = True

       'Set the title of the dialog box.
      .Title = "Select your File"
      
       'Clear out the current filters, and add your own.
      .Filters.Add "Text File", "*.txt"
      .Filters.Add "Comma Separated Value", "*.csv"
      .Filters.Add "All Files", "*.*"
      
      'Set the text of the button Caption
      '.strButtonCaption = "Get File"
      
      '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
          For Each spath In .SelectedItems
          'Show the Path that is selected in a message box
          MsgBox "The path is: " & spath
          'Pass string back to form
          Me!txtfilelocation = spath
          Next spath
       'Show if Canceled is selected in a message box
       Else
          spath = "No File Selected to Import."
          MsgBox spath
          'Pass string back to form
          Me!txtfilelocation = spath
       End If


End With

Thanks!
 

dysfunction

FH is my second home
Joined
Dec 22, 2003
Messages
9,709
Can nobody help me? :(

Anyone suggest a forum I can get help from?
 

dysfunction

FH is my second home
Joined
Dec 22, 2003
Messages
9,709
I managed to get a solution for this. Thanks anyway!
 

Jupitus

Old and short, no wonder I'm grumpy!
Staff member
Moderator
FH Subscriber
Joined
Dec 14, 2003
Messages
3,292
Sorry Dys - I did have a look but it was a bit beyond me without alot of messing around... glad it's sorted :)
 

Users who are viewing this thread

Top Bottom