Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2007, 06:30 AM
Friend of Wrox
 
Join Date: Mar 2007
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
 
Old April 23rd, 2007, 08:53 AM
Friend of Wrox
 
Join Date: Feb 2007
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.

 
Old April 23rd, 2007, 09:07 AM
Friend of Wrox
 
Join Date: Mar 2007
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






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





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