Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating tables via ADO in Access 2007

Posted on 2008-06-24
4
Medium Priority
?
1,082 Views
Last Modified: 2013-11-29
I'm trying to create a table using the attached VBA code.  However, when I try to execute it I get the following error

run-time error
-2147217859 (80040e3d)

The error occurs at line 30 "cat.Tables.Append tbl"  I've used the locals window and it states that the catalog object is no longer valid
Public Sub CreateInvoiceTable()
    Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table
   
    'Create and connect a catalog object
    Set cat = New ADOX.Catalog
    cat.ActiveConnection = CurrentProject.Connection
     
    On Error Resume Next
    
    'If the table already exists, delete it
    cat.Tables.Delete "tblInvoice"
    On Error GoTo 0
    
    'Create the table definition in memory
    Set tbl = New ADOX.Table
    tbl.Name = "tblInvoice"
    
    'Create the new columns
    tbl.Columns.Append "InvoiceNo", adVarChar, 10
    
   
    'Create the remaining columns
    tbl.Columns.Append "InvoiceDate", adDBDate
    tbl.Columns.Append "CustomerID", adInteger
    tbl.Columns.Append "Comments", adVarChar, 50
    Debug.Print tbl.Name
    'Append the new table to the collection
 
    cat.Tables.Append tbl   'Error occurs here
    
  
    
    cat.Tables.Refresh
    Application.RefreshDatabaseWindow
    
    'Clean up
    cat.ActiveConnection = Nothing
    Set tbl = Nothing
    Set cat = Nothing
    
 
End Sub

Open in new window

0
Comment
Question by:chtullu135
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 21861186
try this

Public Sub CreateInvoiceTable()
    Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table
   
    'Create and connect a catalog object
    Set cat = New ADOX.Catalog
    cat.ActiveConnection = CurrentProject.Connection
     
    On Error Resume Next
   
    'If the table already exists, delete it
    cat.Tables.Delete "tblInvoice"
    On Error GoTo 0
   
    'Create the table definition in memory
    Set tbl = New ADOX.Table
    tbl.Name = "tblInvoice"
   
    'Create the new columns
    tbl.Columns.Append "InvoiceNo", adVarWChar, 10
   
   
    'Create the remaining columns
    tbl.Columns.Append "InvoiceDate", adDate
    tbl.Columns.Append "CustomerID", adInteger
    tbl.Columns.Append "Comments", adVarWChar, 50
    Debug.Print tbl.Name
    'Append the new table to the collection
 
    cat.Tables.Append tbl   'Error occurs here
   
 
   
    cat.Tables.Refresh
    Application.RefreshDatabaseWindow
   
    'Clean up
    cat.ActiveConnection = Nothing
    Set tbl = Nothing
    Set cat = Nothing
   
 
End Sub
0
 

Author Comment

by:chtullu135
ID: 21861328
I ran the code you sent and it works.  I did a line by line comparison with my code and could find no difference.  I must be missing something.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 21861375
the lines with '<<<<<  were changed

   tbl.Columns.Append "InvoiceNo", adVarChar, 10      '<<<<<<
   
   
    'Create the remaining columns
    tbl.Columns.Append "InvoiceDate", adDBDate         '<<<<<<
    tbl.Columns.Append "CustomerID", adInteger
    tbl.Columns.Append "Comments", adVarChar, 50    '<<<<<<
0
 

Author Comment

by:chtullu135
ID: 21861544
Thanks for the info.  To be honest I've never run across adVarWChar before.  I'll research it.  Thanks again
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question