Avatar of jbakerstull
jbakerstull

asked on 

Access 07 ADO Runtime error 91

When I run the subroutine with syntax code I receive run time error 91 Object variable or with block variable not set at line rst.ActiveConnection = conn.

I'm not sure exactly why I'm receiving this error. Goal is to display table details via immediate window.

Thanks
Sub Open_Table()
   Dim conn As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim fld As ADODB.Field

    rst.ActiveConnection = conn

   Set conn = New ADODB.Connection
   
   Set rst = New ADODB.Recordset
    
    rst.Open "Select * from tblDisabilityElig", conn, adOpenKeyset, adLockOptimistic
    Do Until rst.EOF
       For Each fld In rst.Fields
          Debug.Print fld.Name & "=" & fld.Value
       Next fld
       rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing
End Sub

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
jbakerstull
SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Also, seems you would need something like


conn = CurrentProject.Connection

mx
Avatar of jbakerstull
jbakerstull

ASKER

Final code is listed below.. thanks for you're help. Learning little more each day.
Sub Open_Table()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field

Set rst = New ADODB.Recordset

'Use the ADO connection that Access uses
Set conn = CurrentProject.AccessConnection

rst.Open "Select * from tblDisabilityElig", conn, adOpenKeyset, adLockOptimistic
    Do Until rst.EOF
       For Each fld In rst.Fields
          Debug.Print fld.Name & "=" & fld.Value
       Next fld
       rst.MoveNext
   Loop
   rst.Close
   Set rst = Nothing
   conn.Close
   Set conn = Nothing

End Sub

Open in new window

Avatar of jbakerstull
jbakerstull

ASKER

Working code is listed in my comments.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo