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

Using ADO Recordset object to populate form

Status
Not open for further replies.

snakehips2000

Programmer
Joined
Nov 10, 2003
Messages
95
Location
GB
I'm trying to populate a form with the results of an ADO recordset which itself is based on a stored procedure.

Can someone please tell me why this code returns the message "Object variable not set" when it gets to the final line?

I've tried putting the routine both in a form module and public module.

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
cn.ConnectionString = MyConnectionString
cn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.CursorType = adOpenDynamic
rs.Open "EXEC " & StoredProcedureName, cn, adopenstatic, adLockoptimistic
'Assign to form
Me.Recordset = rs

Thanks.
 
Hi!

Use the set statement:

[tt]Set Me.Recordset = rs[/tt]

Roy-Vidar
 
Thanks for the quick response Roy-Vidar.

I tried that but then got the error message " The object you entered is not a valid recordset property".

The stored procedure runs OK in Query Analyzer and returns a recordset.
 
I get the same error when using adUseServer as cursorlocation, try using adUseClient.

- short note - if you're using access 2000, using ADO form recordset will make the recordset not updateable if you're using Jet-data. In XP it's updateable.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top