Passing database as argument to procedure

gaidheal

Registered User.
Local time
Today, 03:25
Joined
Oct 7, 2008
Messages
18
I have a database with a procedure that creates a new database and sends information from the source database to the new one. Everything is working fine, except I need to perform an process on both the source and destination database (a renumbering process). Since I have two databases to perform this operation on, I want to use the same code process for both, and pass each database to the procedure. I am getting a Type Mismatch error when I try.
Code - this is for one of the calls, both are essentiall the same, I've left out the non-pertinent parts:

{Procedure that passes the argument}
Private Sub CleanCurrentDb()
Dim Dbs As Database
Dim strSql As String

Set Dbs = CurrentDb
----------
----------
----------
RenumberRecords (Dbs) - this is where the error occurs
----------
----------
end sub

{procedure that receives the argument}
Private Sub RenumberRecords(dbsrenum As Database)
----------
----------
end sub

Either passing a database as an argument doesn't work, or I'm doing something wrong. Any assistance is appreciated.
 
Try using

RenumberRecords(byref dbsrenum As DAO.Database)
 
I tried that, make sense to pass as a reference, but still getting a Type Mismatch error. Is there anything different to be done in the syntax of the call?
 
Remove the parenthesis ...
Code:
RenumberRecords Dbs
... which shouldn't make a difference.
Cheers,
Mark
 
Actually the parentheses do make a difference because they are trying to evaluate an object pointer.

What it amounts to is that an attempt is being made to force a pass by value (ByVal) where an object must be passed by reference (ByRef).
An object can’t be evaluated because it is not the object but just a pointer to the object and pointers can’t be evaluated.

Chris.
 
But isn't the default ByRef in Access?
 
Yes but the parentheses are trying to force an evaluation before the Pass which is why the error occurs on the Pass line:-

RenumberRecords (Dbs)

And not on the Receive line:-

Private Sub RenumberRecords(dbsrenum As Database)

Chris.
 
Removing the parentheses did the trick (along with the byref). Thanks all for your help.
 

Users who are viewing this thread

Back
Top Bottom