By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Use a recordset inside a Function?

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
[Please don't post in HTML]

I don't see anything wrong. Perhaps if you showed us which line generates
the error ...

I do have some suggestions which I will put inline

Bob Barrows

"David Berry" <db****@mvps.org> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
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
This line is unnecessary. If forced to use it, it should be as follows
Set adoRS.ActiveConnection = adoCN

adoRS.CursorLocation = adUseClient

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

If you get rid of the "Set adoRS.ActiveConnection ... " line, then you need
to change this to
adoRS.open strSQL,adoCN,,,adCmdText

Otherwise, it should be:
adoRS.open strSQL,,,,adCmdText
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


Again, nothing sticks out. Is this function in the same script block? You
haven't tried to use a server-side object in a client-side script block,
have you?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From header is
my spam trap, so I don't check it very often. You will get a quicker
response by posting to the newsgroup.
Jul 19 '05 #2

P: n/a
Hi Bob. The line that generates the error is adoRS.movefirst however if I
remove that, ANY line that references the recordset generates the error.
For example: var1= adoRS("Field1") would generate the error.

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

Code that creates the recordset is in a script block at the top of the page
and the function is in a script block about half way down the page. I'm
calling the function near the end of the page. Getting rid of the Set
adoRS.ActiveConnection line and changing it has no effect.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
[Please don't post in HTML]

I don't see anything wrong. Perhaps if you showed us which line generates
the error ...

I do have some suggestions which I will put inline

Bob Barrows

"David Berry" <db****@mvps.org> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
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


This line is unnecessary. If forced to use it, it should be as follows
Set adoRS.ActiveConnection = adoCN

adoRS.CursorLocation = adUseClient

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


If you get rid of the "Set adoRS.ActiveConnection ... " line, then you

need to change this to
adoRS.open strSQL,adoCN,,,adCmdText

Otherwise, it should be:
adoRS.open strSQL,,,,adCmdText
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


Again, nothing sticks out. Is this function in the same script block? You
haven't tried to use a server-side object in a client-side script block,
have you?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From header

is my spam trap, so I don't check it very often. You will get a quicker
response by posting to the newsgroup.

Jul 19 '05 #3

P: n/a
PS - there's no client side code or script block on the page

"David Berry" <db****@mvps.org> wrote in message
news:eu*************@tk2msftngp13.phx.gbl...
Hi Bob. The line that generates the error is adoRS.movefirst however if I
remove that, ANY line that references the recordset generates the error.
For example: var1= adoRS("Field1") would generate the error.

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

Code that creates the recordset is in a script block at the top of the page and the function is in a script block about half way down the page. I'm
calling the function near the end of the page. Getting rid of the Set
adoRS.ActiveConnection line and changing it has no effect.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
[Please don't post in HTML]

I don't see anything wrong. Perhaps if you showed us which line generates the error ...

I do have some suggestions which I will put inline

Bob Barrows

"David Berry" <db****@mvps.org> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
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


This line is unnecessary. If forced to use it, it should be as follows
Set adoRS.ActiveConnection = adoCN

adoRS.CursorLocation = adUseClient

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


If you get rid of the "Set adoRS.ActiveConnection ... " line, then you

need
to change this to
adoRS.open strSQL,adoCN,,,adCmdText

Otherwise, it should be:
adoRS.open strSQL,,,,adCmdText
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


Again, nothing sticks out. Is this function in the same script block? You haven't tried to use a server-side object in a client-side script block,
have you?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From

header is
my spam trap, so I don't check it very often. You will get a quicker
response by posting to the newsgroup.


Jul 19 '05 #4

P: n/a
1. Try declaring the function higher up on the page.
2. Try passing the recordset to the function instead of using the global
variable. I.E.,

adoRs.open ...
....
GetRecords(adoRS)
Function GetRecords(pRS)
if not pRS.BOF then pRS.MoveFirst
'etc.
End Function

David Berry wrote:
PS - there's no client side code or script block on the page

"David Berry" <db****@mvps.org> wrote in message
news:eu*************@tk2msftngp13.phx.gbl...
Hi Bob. The line that generates the error is adoRS.movefirst
however if I remove that, ANY line that references the recordset
generates the error. For example: var1= adoRS("Field1") would
generate the error.

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

Code that creates the recordset is in a script block at the top of
the page and the function is in a script block about half way down
the page. I'm calling the function near the end of the page.
Getting rid of the Set adoRS.ActiveConnection line and changing it
has no effect.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
[Please don't post in HTML]

I don't see anything wrong. Perhaps if you showed us which line
generates the error ...

I do have some suggestions which I will put inline

Bob Barrows

"David Berry" <db****@mvps.org> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
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

This line is unnecessary. If forced to use it, it should be as
follows Set adoRS.ActiveConnection = adoCN
adoRS.CursorLocation = adUseClient

strSQL = "SELECT ... "
adoRS.open strSQL
If you get rid of the "Set adoRS.ActiveConnection ... " line, then
you need to change this to
adoRS.open strSQL,adoCN,,,adCmdText

Otherwise, it should be:
adoRS.open strSQL,,,,adCmdText

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

Again, nothing sticks out. Is this function in the same script
block? You haven't tried to use a server-side object in a
client-side script block, have you?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will
get a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #5

P: n/a
Hi Bob. I just tried both those and I still get object required 'pRS'

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:er**************@tk2msftngp13.phx.gbl...
1. Try declaring the function higher up on the page.
2. Try passing the recordset to the function instead of using the global
variable. I.E.,

adoRs.open ...
...
GetRecords(adoRS)
Function GetRecords(pRS)
if not pRS.BOF then pRS.MoveFirst
'etc.
End Function

David Berry wrote:
PS - there's no client side code or script block on the page

"David Berry" <db****@mvps.org> wrote in message
news:eu*************@tk2msftngp13.phx.gbl...
Hi Bob. The line that generates the error is adoRS.movefirst
however if I remove that, ANY line that references the recordset
generates the error. For example: var1= adoRS("Field1") would
generate the error.

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

Code that creates the recordset is in a script block at the top of
the page and the function is in a script block about half way down
the page. I'm calling the function near the end of the page.
Getting rid of the Set adoRS.ActiveConnection line and changing it
has no effect.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
[Please don't post in HTML]

I don't see anything wrong. Perhaps if you showed us which line
generates the error ...

I do have some suggestions which I will put inline

Bob Barrows

"David Berry" <db****@mvps.org> wrote in message
news:uf*************@tk2msftngp13.phx.gbl...
> 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

This line is unnecessary. If forced to use it, it should be as
follows Set adoRS.ActiveConnection = adoCN

>
> adoRS.CursorLocation = adUseClient
>
> strSQL = "SELECT ... "
> adoRS.open strSQL
>

If you get rid of the "Set adoRS.ActiveConnection ... " line, then
you need to change this to
adoRS.open strSQL,adoCN,,,adCmdText

Otherwise, it should be:
adoRS.open strSQL,,,,adCmdText

> 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

Again, nothing sticks out. Is this function in the same script
block? You haven't tried to use a server-side object in a
client-side script block, have you?

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will
get a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 19 '05 #6

P: n/a
Well, I'm stumped. Is there any chance of posting an abbreviated version of
your page in which this error can be reproduced? Use the Northwind sample
database so we don't have to worry about getting sample data from you.

Bob Barrows

David Berry wrote:
Hi Bob. I just tried both those and I still get object required 'pRS'

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:er**************@tk2msftngp13.phx.gbl...
1. Try declaring the function higher up on the page.
2. Try passing the recordset to the function instead of using the
global variable. I.E.,

adoRs.open ...
...
GetRecords(adoRS)
Function GetRecords(pRS)
if not pRS.BOF then pRS.MoveFirst
'etc.
End Function

David Berry wrote:
PS - there's no client side code or script block on the page

"David Berry" <db****@mvps.org> wrote in message
news:eu*************@tk2msftngp13.phx.gbl...
Hi Bob. The line that generates the error is adoRS.movefirst
however if I remove that, ANY line that references the recordset
generates the error. For example: var1= adoRS("Field1") would
generate the error.

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

Code that creates the recordset is in a script block at the top of
the page and the function is in a script block about half way down
the page. I'm calling the function near the end of the page.
Getting rid of the Set adoRS.ActiveConnection line and changing it
has no effect.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
> [Please don't post in HTML]
>
> I don't see anything wrong. Perhaps if you showed us which line
> generates the error ...
>
> I do have some suggestions which I will put inline
>
> Bob Barrows
>
> "David Berry" <db****@mvps.org> wrote in message
> news:uf*************@tk2msftngp13.phx.gbl...
>> 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
>
> This line is unnecessary. If forced to use it, it should be as
> follows Set adoRS.ActiveConnection = adoCN
>
>>
>> adoRS.CursorLocation = adUseClient
>>
>> strSQL = "SELECT ... "
>> adoRS.open strSQL
>>
>
> If you get rid of the "Set adoRS.ActiveConnection ... " line, then
> you need to change this to
> adoRS.open strSQL,adoCN,,,adCmdText
>
> Otherwise, it should be:
> adoRS.open strSQL,,,,adCmdText
>
>> 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
>
> Again, nothing sticks out. Is this function in the same script
> block? You haven't tried to use a server-side object in a
> client-side script block, have you?
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will
> get a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #7

P: n/a
Bob, I'll have to cut it down to post it. It's a huge page. I'll try and
post it tomorrow when I get back to work. Thanks for the help.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Well, I'm stumped. Is there any chance of posting an abbreviated version of your page in which this error can be reproduced? Use the Northwind sample
database so we don't have to worry about getting sample data from you.

Bob Barrows

David Berry wrote:
Hi Bob. I just tried both those and I still get object required 'pRS'

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:er**************@tk2msftngp13.phx.gbl...
1. Try declaring the function higher up on the page.
2. Try passing the recordset to the function instead of using the
global variable. I.E.,

adoRs.open ...
...
GetRecords(adoRS)
Function GetRecords(pRS)
if not pRS.BOF then pRS.MoveFirst
'etc.
End Function

David Berry wrote:
PS - there's no client side code or script block on the page

"David Berry" <db****@mvps.org> wrote in message
news:eu*************@tk2msftngp13.phx.gbl...
> Hi Bob. The line that generates the error is adoRS.movefirst
> however if I remove that, ANY line that references the recordset
> generates the error. For example: var1= adoRS("Field1") would
> generate the error.
>
> function GetRecords()
> ---->>> adoRS.movefirst
> var1 = adoRS("field1")
> ...........etc
> end function
>
> Code that creates the recordset is in a script block at the top of
> the page and the function is in a script block about half way down
> the page. I'm calling the function near the end of the page.
> Getting rid of the Set adoRS.ActiveConnection line and changing it
> has no effect.
>
>
> "Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
> news:uP**************@TK2MSFTNGP09.phx.gbl...
>> [Please don't post in HTML]
>>
>> I don't see anything wrong. Perhaps if you showed us which line
>> generates the error ...
>>
>> I do have some suggestions which I will put inline
>>
>> Bob Barrows
>>
>> "David Berry" <db****@mvps.org> wrote in message
>> news:uf*************@tk2msftngp13.phx.gbl...
>>> 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
>>
>> This line is unnecessary. If forced to use it, it should be as
>> follows Set adoRS.ActiveConnection = adoCN
>>
>>>
>>> adoRS.CursorLocation = adUseClient
>>>
>>> strSQL = "SELECT ... "
>>> adoRS.open strSQL
>>>
>>
>> If you get rid of the "Set adoRS.ActiveConnection ... " line, then
>> you need to change this to
>> adoRS.open strSQL,adoCN,,,adCmdText
>>
>> Otherwise, it should be:
>> adoRS.open strSQL,,,,adCmdText
>>
>>> 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
>>
>> Again, nothing sticks out. Is this function in the same script
>> block? You haven't tried to use a server-side object in a
>> client-side script block, have you?
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will
>> get a quicker response by posting to the newsgroup.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.