Use a recordset inside a Function?

D

David Berry

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
 
B

Bob Barrows [MVP]

[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 said:
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?
 
D

David Berry

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 said:
[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 said:
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.
 
D

David Berry

PS - there's no client side code or script block on the page



David Berry said:
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 said:
[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 said:
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?
header
is
my spam trap, so I don't check it very often. You will get a quicker
response by posting to the newsgroup.
 
B

Bob Barrows [MVP]

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 said:
PS - there's no client side code or script block on the page



David Berry said:
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 said:
[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

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.
 
D

David Berry

Hi Bob. I just tried both those and I still get object required 'pRS'



Bob Barrows said:
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 said:
PS - there's no client side code or script block on the page



David Berry said:
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.


[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

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.
 
B

Bob Barrows [MVP]

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 said:
Hi Bob. I just tried both those and I still get object required 'pRS'



Bob Barrows said:
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 said:
PS - there's no client side code or script block on the page



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.


[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

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.
 
D

David Berry

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 said:
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 said:
Hi Bob. I just tried both those and I still get object required 'pRS'



Bob Barrows said:
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



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.


[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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top