jessa_lee
Registered User.
- Local time
- Today, 20:10
- Joined
- Oct 14, 2003
- Messages
- 40
This is the code I took directly from a book I'm learning VBA from, and when I run it, I get a "Compile Error: User-defined type not defined" on the second line - "Dim Table As New Table", as well as any of the lines with "ADOX" or "ADODB" on them.
Sub CreateTable()
Dim Table As New Table
Dim Catalog As New ADOX.Catalog
Dim Key As New ADOX.Key
Catalog.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=H:/Projects/contacts.mdb"
Table.Name = "NewContacts"
Table.ParentCatalog = Catalog
Table.Columns.Append "ID", adInteger
Table.Columns("ID").Properties("AutoIncrement") = True
Table.Columns.Append "FName", adVarWChar, 20
Table.Columns.Append "LName", adVarWChar, 20
Table.Columns.Append "PhNum", adVarWChar, 36
Table.Columns.Append "Email", adVarWChar, 50
Table.Columns.Append "WWW", adVarWChar, 50
Catalog.Tables.Append Table
Key.Name = "ID"
Key.Type = adKeyPrimary
Key.Columns.Append "ID"
Catalog.Tables("NewContacts").Keys.Append Key, kyPrimary
Set Catalog.ActiveConnection = Nothing
End Sub
What am I missing?
Sub CreateTable()
Dim Table As New Table
Dim Catalog As New ADOX.Catalog
Dim Key As New ADOX.Key
Catalog.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=H:/Projects/contacts.mdb"
Table.Name = "NewContacts"
Table.ParentCatalog = Catalog
Table.Columns.Append "ID", adInteger
Table.Columns("ID").Properties("AutoIncrement") = True
Table.Columns.Append "FName", adVarWChar, 20
Table.Columns.Append "LName", adVarWChar, 20
Table.Columns.Append "PhNum", adVarWChar, 36
Table.Columns.Append "Email", adVarWChar, 50
Table.Columns.Append "WWW", adVarWChar, 50
Catalog.Tables.Append Table
Key.Name = "ID"
Key.Type = adKeyPrimary
Key.Columns.Append "ID"
Catalog.Tables("NewContacts").Keys.Append Key, kyPrimary
Set Catalog.ActiveConnection = Nothing
End Sub
What am I missing?