Solved

Public recordset

Posted on 2006-07-13
10
184 Views
Last Modified: 2010-04-30
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
Comment
Question by:thenone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17105300
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
 
LVL 8

Author Comment

by:thenone
ID: 17105311
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
 
LVL 35

Expert Comment

by:Raynard7
ID: 17105333
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Comment

by:thenone
ID: 17105359
I am using mysql 5.0 which does recognize limit I can do a regular query and it returns 2.
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17105380
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
 
LVL 8

Author Comment

by:thenone
ID: 17105396
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
 
LVL 35

Expert Comment

by:Raynard7
ID: 17105426
Yes; else you will go too far - ie record 3;
also note my code above needs an end if at the end
0
 
LVL 8

Author Comment

by:thenone
ID: 17105433
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
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
ID: 17105482
Reference the label name
ie
Me.label1 = rs!FieldName
0
 
LVL 8

Author Comment

by:thenone
ID: 17105541
so label.caption = rs!fieldname
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question