How to ImportSpreadsheet with a variable file name

Jackass

New Member
Joined
Jul 16, 2015
Messages
4
Hi,

Anyone please helping me!!!
I'm very newbie
I've been create MS access and want to import file by browse and select file to import.
I have 1 text box name "Text01" (will show path and file name to import)
I have 1 button for browse file name "btbrowse" (Browse to select file)
I have 1 button for run command import excel to table it's name "Import"
and in database i have table name "T_DataFingerScan" to receive data from import

p.s. I can use macro to import but in macro cannot browse file so please give me for suggestion.

Regards,
Jackass
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
1 user clicks button to select a file to import
2. once selected , run docmd.TransferSpreadsheet to import the data

see code below to select a file in the button click:
usage:
txtBox = UserPick1File("c:\folder\")




Code:
'NEW VERSION
Public Function UserPickFile(byval pvPath)
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr  As String, sExt As String
dim fd as filedialog


set fd = Application.FileDialog(msoFileDialogFilePicker)  '<---- 'MUST ADD REFERENCE : Microsoft Office 11.0 Object Library
With fd
    .AllowMultiSelect = False
    .Title = "Locate a file to Import"
    .ButtonName = "Import"
    .Filters.Clear
    .Filters.Add "All Files", "*.*"
    .InitialFileName = "c:\"
    .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
    ''.AllowMultiSelect = True
     
        If .show = 0 Then
           'There is a problem
           Exit Function
        End If
    
    'Save the first file selected
    UserPick1File = Trim(.SelectedItems(1))
End With
set fd = nothing
End Function
 
Upvote 0
Ranman256 very thanks for your answer.
How can i apply for my access by detail as below?

I have 1 text box name "Text01" (will show path and file name to import)
I have 1 button for browse file name "btbrowse" (Browse to select file)
I have 1 button for run command import excel to table it's name "Import"
and in database i have table name "T_DataFingerScan" to receive data from import
 
Upvote 0

Forum statistics

Threads
1,217,124
Messages
6,134,763
Members
449,888
Latest member
webarnes99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top