Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-21-2004, 03:26 AM   #1
Member (8 bit)
 
Join Date: Aug 2003
Location: SoCal
Posts: 178
VBA Access test program

I'm going through my Access Programming book, and finally in Chapter 6 we start actually writing programs. I type in the example program from the book and... it doesn't work. I am using Microsoft Access 2002 (10.2616.2625) and Microsoft Visual Basic 6.3.8863. It also uses Microsoft ADO Ext. 2.8 for DDL and Security.

Here is the test program I copied out of the book, it is intended to create a table named CONTACTS in the preexisting Contacts.mdb database:

Sub CreateTable()
Const DatabasePath = "C:\My Documents\Database Projects\Contacts.mdb"
Const ProviderStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DatabasePath
Dim Table As New Table
Dim Catalog As New ADOX.Catalog
Dim Key As New ADOX.Key
***Catalog.ActiveConnection = ProviderStr***
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, adKeyPrimary
Set Catalog.ActiveConnection = Nothing

End Sub

When I try to run it in the editor, it gives me an error on the line that's singled out with the *'s above. The error is "Run-time error '-2147467259 (80004005)': Could not use "; file already in use."

I'm very new to using VBA in Access and I have no idea what's causing this error. As far as I can tell, I copied everything precisely out of the book, and I'd like this program to actually do something before I move on.
jong2k4 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:14 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2