Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 20th, 2007, 06:30 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default Passing ADO Recordset ByVal

Afternoon All,

Can anyone shed any light on this for me?

I am passing an ADO Recordset to a function (which basically scans through, performs some logic and then returns an Array of Record ID's based on the logic result). I am passing the Recordset to it ByVal, as I not want the cursor to move in the Recordset, I just want the results.

However, it appears that it is actually still being passed ByRef??
.EOF is False before calling the procedure, and True once the procedure has completed. Of course, I know VBA is ByRef by default, and I have put ByVal in the parameters for the function.

Does anyone know of ByVal being overridden for ADO Objects? Could it be because of the Cursor Type/Location etc? The recordset passed is a ROFO (read-only, forward only) Recordset.

Just curious as to why this is occurring, I can work around it, but confused as to why I should!

Many thanks,
Rob

__________________
Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #2 (permalink)  
Old April 23rd, 2007, 08:53 AM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The connection to the recordset is the same regardless of how it is passed. If you want to return the pointer to a certain record once processing from a subroutine or function is done you'd have to store the current position and return to it once the function is finished. This also applies for any filter(s) set or removed.

Another way you could do this, if you need both instances for whatever reason, is to have the subroutine or function open it's own connection to the table. Don't forget to close any code opened connections before the code finishes processing to help prevent orphaned connections.

Reply With Quote
  #3 (permalink)  
Old April 23rd, 2007, 09:07 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi allenm,

Thanks for your response to this, I done some digging the other day and found out that all Objects are passed ByRef, irrespective as to wether you specify ByVal or ByRef.

From what I can gather, this does not occur in .NET (could be wrong) but from the small amount of .NET stuff I have done, I dont remember this happening.

At least I now know, that you cannot pass an ADO object (or any object) ByVal in VBA...

Thanks for the reply though, much appreciated.

Regards,
Rob

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
ADO recordset to table kanoorani VB Databases Basics 3 May 16th, 2006 02:59 AM
ADO Recordset Scootterp Access VBA 4 February 27th, 2006 06:44 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM
Crystal Report From ADO Recordset Niaz Pro VB Databases 0 January 11th, 2004 04:01 AM



All times are GMT -4. The time now is 12:59 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.