Having trouble with a TableDef object...
-
I would like to be able to add a field to an existing table in Microsoft Access. It is my understanding that I would need to use a TableDef object. Could you give me some insights? The code I have now is like so:
Option Compare Database
Public dbsHeadcount As Database
Public Cnxn As ADODB.Connection
Public rstHyperionMany As ADODB.RecordsetFunction ProcessHeadcountFile()
On Error GoTo ErrorHandlerDim strConn As String Dim rstLoadFile As ADODB.Recordset Dim cmdSQLLoadFile As ADODB.Command Dim strSQLLoadFile As String Dim rstHyperionOne As ADODB.Recordset Dim cmdSQLHyperionOne As ADODB.Command Dim strSQLHyperionOne As String Dim cmdSQLHyperionMany As ADODB.Command Dim strSQLHyperionMany As String Dim strFileName As String Dim qdfTemp As QueryDef Dim qdfNew As QueryDef Dim strHoldRecString As String Dim strMessage As String Set dbsHeadcount = OpenDatabase("J:\\\\Headcount Database.mdb") Set Cnxn = New ADODB.Connection strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & \_ "Data Source=J:\\\\Headcount Database.mdb;" Cnxn.Open strConn Call LoadExcelIntoAccessTable Set cmdSQLInputFile = New ADODB.Command Set cmdSQLInputFile.ActiveConnection = Cnxn Set cmdSQLHyperionMany = New ADODB.Command Set cmdSQLHyperionMany.ActiveConnection = Cnxn strSQLHyperionMany = "SELECT \[COUNTRY\], \[TYPE\], \[BUSINESS UNIT\], " & \_ "\[L/R/G\], \[REGION\], \[JOB FUNCTION\], \[09/12/2007 Reported\] " & \_ "FROM \[tblInputFile\]" cmdSQLHyperionMany.CommandType = adCmdText cmdSQLHyperionMany.CommandText = strSQLHyperionMany Set rstHyperionMany = cmdSQLHyperionMany.Execute() rstHyperionMany.MoveFirst Call CreateIndexesForLoadedTable
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & ":" & Err.Description, , "Error and Error #" & Err.Number
End If
End FunctionSub LoadExcelIntoAccessTable()
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tblInputFile", "C:/Employees.xls", True
End SubSub CreateIndexesForLoadedTable()
Dim tdfInputFile As TableDef
Set tdfInputFile = dbsHeadcount.CreateTableDef("tblInputFile")
tdfInputFile.Fields.Append tdfInputFile.CreateField("Date", dbDate)
dbsHeadcount.TableDefs.Append tdfInputFileERROR: Here is where it is saying that tblInputFile already exists. How do I append the field called "Date" to the existing table called tblInpu