Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb6 and access report - variable not defined

Status
Not open for further replies.

jozino01

Technical User
Apr 25, 2003
257
CA
hi,
i am getting an error message "variable not defined" (Load rptDetails) when running the following code:

Dim objAccessConnection As ADODB.Connection
Dim RSACCESS As ADODB.Recordset
Dim SQL As String

Set objAccessConnection = New ADODB.Connection
objAccessConnection.CursorLocation = adUseClient

objAccessConnection.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\dinsys\invoice.mdb;"

SQL = "Select * From lumlot where [inv]=158"
Set RSACCESS = New ADODB.Recordset
RSACCESS.Open SQL, objAccessConnection, adOpenKeyset, adLockOptimistic

If Not RSACCESS.EOF Then
Load rptDetails
With rptDetails
Set .DataSource = RSACCESS
.Show
End With
Else
MsgBox "no data to display", vbInformation
End If

RSACCESS.Close
Set RSACCESS = Nothing

am i missing soemthing in references (i already have MS access 9.0 Library there) or is't something else?

i didn't touch vb for almost an year now and need to refresh it a bit...
 
Well, your variable hasn't been defined. It's looking for some such thing as
Code:
Dim rptDetails as SomeKindOfType
because you don't have a control on your form called rptDetails, or you don't have a form called rptDetails (form names ought to begin with frm though).

Give more background about what rptDetails is supposed to be, and maybe I can help more.

HTH

Bob
 
rptDetails is the name of an existing report in that database.
 
i also tried 'dim rptdetails as accessobject' and got an error 'object variable or with block variable not set'
 
All right. It doesn't look like you're using VB6, rather it looks like you're using Access and VBA. You might find more success in that forum. I don't know much about how to access report objects in Access. However, I'll give you a bit of background on how objects work both in VB6 and VBA.

When you say
Code:
Dim myObject as SomeClass
that declares the variable. If you get an error on this line, it means that SomeObject isn't recognized as an object type.

After you declare the variable, you have to "instantiate" the object. You do this on another line:
Code:
Set myObject = New SomeClass
If you don't do that, when you reference it, you'll get the "object variable or with block variable not set" error.

The other thing you can do is set your variable to an existing instance of a class, i. e. an existing object. When you run VB6, a form is (generally) created automatically. You can reference that form:
Code:
Dim myObject as Form
Set myObject = Form1
This will work. So, in Access, a number of objects (for example, the database object, your forms, and I believe your reports) are all created automatically when you run Access and execute something from VB. If you need more help on what gets created when, perhaps you'll go to the other forum.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top