Appending a Table to a Catalog using ADOX
I am trying to have some VBA code create an error table for me when importing data. I duplicated an example from my WROX book (Access 2003 VBA) and modified it for additional columns in the table. Unfortunately, I keep getting this message:
"Run-time error '-2147217859 (80040e3d)': Type is invalid", which the debugger points to the line "cat.Tables.Append tbl" (this is verbatim from the book)
Could anyone point me in the right direction please?
************************************************** ********************
Public Sub CreateErrorTable()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
On Error Resume Next
cat.Tables.Delete "Input_Errors"
On Error GoTo 0
Set tbl = New ADOX.Table
tbl.Name = "Input_Errors"
tbl.Columns.Append "ST", adVarChar, 50
tbl.Columns.Append "Region", adVarChar, 50
tbl.Columns.Append "BrNum", adInteger
tbl.Columns.Append "BrName", adVarChar, 50
tbl.Columns.Append "FeesCharged", adCurrency
tbl.Columns.Append "SumofMyBranch", adCurrency
tbl.Columns.Append "DiscretionWaiver", adCurrency
tbl.Columns.Append "Discretionary", adCurrency
tbl.Columns.Append "SustainedAssessed", adCurrency
tbl.Columns.Append "CourtesyWaiver", adCurrency
tbl.Columns.Append "File Date", adDBDate
cat.Tables.Append tbl '<-- this is the line debug points to
cat.Tables.Refresh
cat.ActiveConnection = Nothing
Set tbl = Nothing
Set cat = Nothing
End Sub
|