JFRobishow
Technical User
Hi everyone,
I'm trying to get my application to create a new table in an Access 2002 database. I've been reading for a while and see that it can be done with DAO but that doesn't work with Access 2002 right?
Since I've never learned database programming I thought I would go with ADO but in MSDN it say that you can't create table with ADO but that you can with ADOX...so I've googled around trying to find a way but I'm stuck...
I've found a code sample :
Sub CreateAccessTable(strDBPath As String)
Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Set catDB = New ADOX.Catalog
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
Set tblNew = New ADOX.Table
' Create a new Table object.
With tblNew
.Name = "Contacts"
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar
.Append "Notes", adLongVarWChar
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set catDB = Nothing
End Sub
That doesn't work, it give error since the data type (ADOX.Catalog) is not defined and probably the one below as well. Is ADOX part of VB.NET only or is it available for VB 6? I did a search on my PC and I do have msadox.dll (176KB) on my PC (in two locations) but I don't know how to use it.
Is there any other way to create table with VB6?
Thanks in advance for any suggestions or links.
I'm trying to get my application to create a new table in an Access 2002 database. I've been reading for a while and see that it can be done with DAO but that doesn't work with Access 2002 right?
Since I've never learned database programming I thought I would go with ADO but in MSDN it say that you can't create table with ADO but that you can with ADOX...so I've googled around trying to find a way but I'm stuck...
I've found a code sample :
Sub CreateAccessTable(strDBPath As String)
Dim catDB As ADOX.Catalog
Dim tblNew As ADOX.Table
Set catDB = New ADOX.Catalog
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
Set tblNew = New ADOX.Table
' Create a new Table object.
With tblNew
.Name = "Contacts"
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar
.Append "Notes", adLongVarWChar
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set catDB = Nothing
End Sub
That doesn't work, it give error since the data type (ADOX.Catalog) is not defined and probably the one below as well. Is ADOX part of VB.NET only or is it available for VB 6? I did a search on my PC and I do have msadox.dll (176KB) on my PC (in two locations) but I don't know how to use it.
Is there any other way to create table with VB6?
Thanks in advance for any suggestions or links.