[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Public recordset

inside one function I have a recordset that opens and I want to be able to use the same recordset with another function how can I do that?
0
thenone
Asked:
thenone
  • 5
  • 5
1 Solution
 
Raynard7Commented:
The best way would be to pass it to the other function

ie
function1() as string
dim x as ADODB.recordset
function2(x)
end function

function2(useThatRecordset as ADODB.recordset)
'do stuff with the recordset that was passed to it
end function

alternativley

you could dim the recordset at the start of the module (making it available to all functions inside that module)
the first function could set that recordset = to something
but not close it

the second function would then have access to the same recordset.
0
 
thenoneAuthor Commented:
well the thing is I have a function that rs.open"Select * from table limit 2"

well when I loop through the function i think it doesn't limit to the 2 records.
0
 
Raynard7Commented:
What database are you querying - not all recognise limit; ie MS Access - others; like oracle use rownum <= 2 to limit it to 2 records.
If you want to limit it to two records you could do

rs.open "select * from ..."
rs.movefirst
if (rs.eof <> rs.bof) then
dim counter as long
counter = 1
do while not rs.eof
  .......
  rs.movenext
  counter = counter + 1
  if counter > 2 then exit do
loop
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
thenoneAuthor Commented:
I am using mysql 5.0 which does recognize limit I can do a regular query and it returns 2.
0
 
Raynard7Commented:
Limit definitley should be working - it may return 1 row if that is all there is but limit will definitley restrict it to 2 rows
0
 
thenoneAuthor Commented:
Thats what I have done but it seems like its going past that.For every recordset.movenext do I need to increment a counter to get end of
0
 
Raynard7Commented:
Yes; else you will go too far - ie record 3;
also note my code above needs an end if at the end
0
 
thenoneAuthor Commented:
ok I figured it out finally after two days yeah!!!! One last question and I will post points.If I do a recordset move like this how can I dsipaly what record I am on in a label?
0
 
Raynard7Commented:
Reference the label name
ie
Me.label1 = rs!FieldName
0
 
thenoneAuthor Commented:
so label.caption = rs!fieldname
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now