Hi guys... I found this code online:
As you can see from above i am getting a Specified cast is not valid error on this line. I have looked online and it says to reference ADO 2.7 DLL with security.... but i can only find 2.8 and 6.0 in my reference list.. Please help
Sub Main()
Dim Cn As OleDb.OleDbConnection, Cat As ADOX.Catalog, _
objTable As ADOX.Table
Cn = New OleDb.OleDbConnection
Cat = New ADOX.Catalog
objTable = New ADOX.Table
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\DJ Warp\Desktop\My Apps\NewMDB.mdb"
'Open the connection
Cn.Open()
'Open the Catalog
Cat.ActiveConnection = Cn '<<<<<<<Error Occurs Here
'Create the table
objTable.Name = "Test_Table"
'Create and Append a new field to the "Test_Table"
'Columns Collection
objTable.Columns.Append("PrimaryKey_Field", DataTypeEnum.adInteger)
'Create and Append a new key. Note that we are merely passing
'the "PimaryKey_Field" column as the source of the primary key.
'Thi snew Key will be Appended to the Keys Collection of
'"Test_Table"
objTable.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, _
"PrimaryKey_Field")
'Append the newly created table to the Tables Collection
Cat.Tables.Append(objTable)
' clean up objects
'objKey = Nothing
objTable = Nothing
Cat = Nothing
Cn.Close()
Cn = Nothing
End Sub
As you can see from above i am getting a Specified cast is not valid error on this line. I have looked online and it says to reference ADO 2.7 DLL with security.... but i can only find 2.8 and 6.0 in my reference list.. Please help