|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|