Use a recordset inside a Function?

From: David Berry (dberry_at_mvps.org)
Date: 06/23/04


Date: Wed, 23 Jun 2004 15:03:05 -0400

I'm trying to use a recordset inside of a function but I'm getting an "object required 'adoRS" error.

At the top of the page I create my recordset, ex:

dim strConnection, adoCN, adoRS, strSQL

strConnection = <Connection>
Set adoCN = server.CreateObject("ADODB.connection")
Set adoRS = server.CreateObject("ADODB.recordset")
adoCN.Open strConnection
adoRS.ActiveConnection = adoCN
adoRS.CursorLocation = adUseClient

strSQL = "SELECT ... "
adoRS.open strSQL

then further down the page I call a function GetRecords(). The function looks like this:

function GetRecords()
    adoRS.movefirst
    var1 = adoRS("field1")
       ...........etc
end function

I'd rather not have the whole recordset inside of the function since I also use it on other parts of the page. What am I doing wrong?

Thanks



Relevant Pages