Creating Table in module

M

Marco Simone

Hi,

I am reading book of Access programming. I have code for creating table and
is not working. Can someone help.

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;Data
Source=C:\Document\contacts.mdb"
Table.Name = "CONTACTS"
Table.ParentCatalog = Catalog
Table.Columns.Append "ID", adInteger
Table.Columns("ID").Properties("AutoIncrement") = True
Table.Columns.Append "FIRST_NAME", adVarWChar, 20
Table.Columns.Append "LAST_NAME", adVarWChar, 20
Table.Columns.Append "PHONE_NUMBER", 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("CONTACTS").Keys.Append Key
Set Catalog.ActiveConnection = Nothing
End Sub

When I start code (F5) I get error message: "The database has been placed in
a state by user 'Admin' on machine 'Comp' that it prevents from being opened
or locked."
This line is highlighted :
Catalog.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Document\contacts.mdb"
I am beginner, this is my level of access at the moment.

Thanks in advance, Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top