shieldsco
asked on
Access Add Excel File Name to Import Table
I'm using the following code to import an Excel file and I would like to add the Excel file name to the import table ,,,, tblReceiptIndex
Private Sub cmdImport_Click()
Dim oXL As Object
Dim wkb As Object
Dim wks As Object
Set oXL = CreateObject("excel.application")
On Error GoTo Err_Handler
Set wkb = oXL.Workbooks.Open(Me.txtFileName)
oXL.Quit
Set oXL = Nothing
DoCmd.SetWarnings False
If IsNull(Me.txtFileName) Or Len(Me.txtFileName & "") = 0 Then
MsgBox "please select excel file"
Me.cmdSelect.SetFocus
Exit Sub
End If
'Delete records in the temp table
DoCmd.OpenQuery "qryDelReceiptsIndex"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tblReceiptIndex", Me.txtFileName, True
Private Sub cmdSelect_Click()
Dim strStartDir As String
Dim strFilter As String
Dim lngFlags As Long
' Lets start the file browse from our current directory
strStartDir = CurrentDb.Name
strStartDir = Left(strStartDir, Len(strStartDir) - Len(Dir(strStartDir)))
strFilter = ahtAddFilterItem(strFilter, _
"Excel Files (*.xls*)", "*.xls*")
Me.txtFileName = ahtCommonFileOpenSave(InitialDir:=strStartDir, _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Select File")
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Open in new window