Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating table using ADO?? Access 2002 2

Status
Not open for further replies.

JFRobishow

Technical User
Jun 18, 2003
87
CA
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.
 
Add a reference to Microsoft ADO Ext. X.X for DLL and Security and it should work.

Swi
 
Go to Project|References and tick the Microsoft ADO Ext 2.x for DDL and Security.

It should work then

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
You guys rock! It work :)

Thanks to both of you, Swi for the answer and johnwm for the quick reply just as I was googling around on how to add a reference :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top