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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't use an ADO recordset object after passing it to a class module.

Status
Not open for further replies.

lwatanabe

Programmer
Jul 22, 2001
13
US
What is supposed to be a rather elementary piece of code is beginning to become a huge problem for me.

I have been coding an ActiveX control, with a TreeView control, to manipulate a disconnected ADO recordset (name rsMenu). I also have a class module (within the same project) that needs to reference that recordset.

It seems that I can pass the recordset to the class just fine, but when I try to actually USE the recordset (i.e. the .movefirst method) I get a "Object or with block variable not set".

In my activeX control I have setup the recordset as follows.

Private dbCONN as ADODB.Connection
Private rsMenu as ADODB.Recordset
Private cmdMenu as ADODB.Command

Set dbCONN = New ADODB.Connection
Set rsMenu = New ADODB.Recordset
Set cmdMenu = New ADODB.Command

dbCONN.ConnectionString = "Driver={SQL Server};" & _
"Server=Starweb;" & _
"Uid=usr_starnet;" & _
"Pwd=usr_starnet;" & _
"Database=Starnet;"
dbCONN.Open

cmdMenu.ActiveConnection = dbCONN
cmdMenu.CommandTimeout = 600
cmdMenu.CommandText = "select * from menu order by linkid "
cmdMenu.CommandType = 1 'adCmdText

rsMenu.LockType = adLockBatchOptimistic
rsMenu.CursorLocation = adUseClient
rsMenu.CursorType = adOpenStatic
rsMenu.Open cmdMenu

rsMenu.ActiveConnection = Nothing
rsMenu.MarshalOptions = adMarshalModifiedOnly

... then I instantiate my class later in my code with ...

Dim SourceInfo as NodeInfo
Set SourceInfo = New NodeInfo
SourceInfo.Reference = rsMenu

... my class is defined as follows (simplistic)...

Private m_rsReference as ADODB.Recordset

Public Property Let Reference(blah as ADODB.Recordset)
Set m_rsReference = blah
End Property

Apparently, the recordset is being passed to the class module correctly, but something happens to it in the passing because I get that horrific "Object variable or with block variable not set" error when trying to do any operations on it. Like the following...

If TypeName(m_rsReference)<>&quot;Recordset&quot; Then
Exit Sub
Else
m_rsReference.MoveFirst <--- Offending line of code.
End If

--This seems like such an elementary problem can someone help me resolve this?
 
You're setting a property in a class equal to an object.
My first instinct would be to use:

Code:
set SourceInfo.Reference = rsMenu


Just a suggestion.. without further investigation I can't be sure..


--
Anyone reading this, regardless of nationality or religion, please take a moment of silence or pray for the people of New York City, USA, for their friends and family, and for all of the lives lost both in the planes and in the Two Towers of the World Trade Center, and the Pentagon.

Thank you.

-- NipsMG

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top