add file name to a table after import (1 Viewer)

sspreyer

Registered User.
Local time
Today, 03:20
Joined
Nov 18, 2013
Messages
251
hi all

i have some code that i use to import data from excel
Code:
Dim SelectedFile    As String
Dim FilePicker      As FileDialog
Dim SQLdelete       As String

Set FilePicker = Application.FileDialog(msoFileDialogFilePicker)
FilePicker.AllowMultiSelect = False
FilePicker.Filters.Add "Excel", "*.xls*", 1
FilePicker.InitialFileName = "C:\Users\"
FilePicker.Title = "Please Select the Excel Data..."
FilePicker.Show

If FilePicker.SelectedItems.Count <> 0 Then
    SelectedFile = FilePicker.SelectedItems(1)
    
 



        DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblExcelImport", SelectedFile, True, "A4:E"


    MsgBox ("The data has been successfully loaded")
End If
End Sub

but want to be able to get the selected filename add it to another table called tblexcelfilename once the import is done

any help much appreciated

shane
 

Ranman256

Well-known member
Local time
Today, 06:20
Joined
Apr 9, 2015
Messages
4,337
Can you run an update after the Import?

Docmd.Transferspreadsheet...
SSql= "update tblExcelImport set [filename]='" & SelectedFile & "' where [filename] is null"
Docmd.runSql sSql
 

sspreyer

Registered User.
Local time
Today, 03:20
Joined
Nov 18, 2013
Messages
251
Can you run an update after the Import?

Docmd.Transferspreadsheet...
SSql= "update tblExcelImport set [filename]='" & SelectedFile & "' where [filename] is null"
Docmd.runSql sSql

thanks
sorry that won't work because i'm importing in to tblexcelimport but really wanted the file name to go in tblexcelfilename
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:20
Joined
Sep 21, 2011
Messages
14,261
Assuming you want a date it was imported as well?

Code:
sSQL="INSERT INTO tblexcelfilename ( ImportDate, Fname )"
sSQL = sSQL & " SELECT Date() AS ImportDate, '" & SelectedFile & "' AS FName"
Docmd.runSql sSql
 
Last edited:

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 06:20
Joined
Oct 17, 2012
Messages
3,276
Here's a silly question: Do you want just the file name, or the whole path?
 

Users who are viewing this thread

Top Bottom