Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 23rd, 2005, 09:52 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADOX problem

Hi all,

Im new to this forum and also new to VBA
I'm trying to use ADOX to get the list of tables, procedures and view using ADOX but get an error
"Run-time error '91'; Object variable or With block variable not set"

my code is shown below. I have added the ADO Ext. 2.7 DDL and Security library but the strange thing is the ADOX's comes back in lower case when all the others convert to upper case as I type. Could anyone shed some light on this please? thank you

Code:
Sub adox()
    Dim cat As adox.Catalog
    Dim cnn1 As ADODB.Connection
    Dim tbl As adox.Table
    Dim proc As adox.Procedure
    Dim vie As adox.View

    Set cnn1 = CurrentProject.Connection

    cat.ActiveConnection = cnn1

    For Each tbl In cat.Tables
        Debug.Print "Tablename: " & tbl.Name
    Next

    For Each proc In cat.Procedures
        Debug.Print "proc: " & proc.Name
    Next

    For Each vie In cat.Views
        Debug.Print "view: " & vie.Name
    Next

    Set cnn1 = Nothing


End Sub
 
Old December 23rd, 2005, 10:34 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found the problem ^^

When using the current connection the catalog object is not initiated, hence need to create one and specify the current connection. here is the code. hope this helps newbies

Code:
Public Sub adoxs()
    Dim cat As adox.Catalog
    Dim cn As ADODB.Connection
    Dim tbl As adox.Table
    Dim proc As adox.Procedure
    Dim vie As adox.View

    'Set cn = CurrentProject.Connection
    Set cat = New adox.Catalog
    Set cat.ActiveConnection = CurrentProject.Connection

    For Each tbl In cat.Tables
        Debug.Print "Tablename: " & tbl.Name
    Next

    For Each proc In cat.Procedures
        Debug.Print "proc: " & proc.Name
    Next

    For Each vie In cat.Views
        Debug.Print "view: " & vie.Name
    Next

    Set cn = Nothing


End Sub




Similar Threads
Thread Thread Starter Forum Replies Last Post
ADOX: Changing the view of a boolean swenni Access 3 January 6th, 2007 07:02 AM
ADOX speedlearner BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 June 23rd, 2006 04:15 PM
Create a Table using ADOX JDrown Access VBA 7 April 12th, 2006 03:52 AM
ADOX/MDAC Problem r4ross Access VBA 2 December 2nd, 2005 10:39 AM
Dynamic queries without ADOX gpet Access 0 June 10th, 2005 01:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.