I am trying to use transferspreadsheet to import access worksheet and then I want to append additional fields. I am able to import the excel sheet into access, but need help appending the other fields.
In the code below, how can I do the piece in red?
In the code below, how can I do the piece in red?
Code:
Dim fd2 As FileDialog
Dim xlapp As New Excel.Application
Dim xlsht As Excel.Worksheet
Dim xlWrkBk As Excel.Workbook
Dim db As DAO.Database
Dim tb2 As TableDef
Dim fdx, fld As DAO.Field
Private Sub Append_File_Click()
et fd2 = Application.FileDialog(msoFileDialogFilePicker)
With fd2
.Show
For Each vrtSelected In .SelectedItems
Set xlapp = CreateObject("Excel.application")
Set xlWrkBk = GetObject(vrtSelected)
Set xlsht = xlWrkBk.Worksheets(1)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, TableName:="my_table", FileName:=vrtSelected, HasFieldNames:=True
With [COLOR=red]"the table I just imported"
[/COLOR]
Set fld = .CreateField("Name", dbText)
.Fields.Append fld
Set fld = .CreateField("Birthdate", dbDate)
.Fields.Append fld
End With
db.TableDefs.Append tb2
Next vrtSelected
End With