import excel data into existing access table using vba

wejdan1994

New member
Local time
Today, 12:00
Joined
Mar 29, 2020
Messages
10
Hello everyone,

I would like to ask you if you have example file to import (append) data from excel to existing access table via vba codes ?

Note: the code does not contain a specific Excel name.


thank you,
 
Hi. Have you tried the TransferSpreadsheet method?
 
From external data tab ?
I need form that enable me to import data from any formatted excel to existing table in access
 
From external data tab ?
I need form that enable me to import data from any formatted excel to existing table in access
No, by using VBA. That's what you asked for, right? Have you tried it?
 
Private Sub btnImportSpreadsheet_Click()
Dim FSO As New FileSystemObject

If Nz(Me.txtFileName, "") = "" Then
MsgBox "Please select a file!"
Exit Sub
End If

If FSO.FileExists(Nz(Me.txtFileName, "")) Then
ExcelImport.ImportExcelSpreadsheet Me.txtFileName, FSO.GetFileName(Me.txtFileName)
Else
MsgBox "File not found!"
End If

End Sub


I only tried this code, but this code used to import data from excel to new table not to specific table. otherwise no
 
Private Sub btnImportSpreadsheet_Click()
Dim FSO As New FileSystemObject

If Nz(Me.txtFileName, "") = "" Then
MsgBox "Please select a file!"
Exit Sub
End If

If FSO.FileExists(Nz(Me.txtFileName, "")) Then
ExcelImport.ImportExcelSpreadsheet Me.txtFileName, FSO.GetFileName(Me.txtFileName)
Else
MsgBox "File not found!"
End If

End Sub


I only tried this code, but this code used to import data from excel to new table not to specific table. otherwise no
I suggest you try it and let us know how it goes.
 
Solved, appreciated.
I used the below Code:

Public Sub ImportExcelSpreadsheet(fileName As String, tableName As String)
On Error GoTo BadFormat
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "EmpDoc", fileName, True
Exit Sub

BadFormat:
MsgBox "The file you tried to import was not an Excel spreadsheet."
End Sub



Note: EmpDoc = access table name
 
Solved, appreciated.
I used the below Code:

Public Sub ImportExcelSpreadsheet(fileName As String, tableName As String)
On Error GoTo BadFormat
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "EmpDoc", fileName, True
Exit Sub

BadFormat:
MsgBox "The file you tried to import was not an Excel spreadsheet."
End Sub



Note: EmpDoc = access table name
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom