Database Parameter in my Function statement

  • Thread starter Thread starter Joy M
  • Start date Start date
J

Joy M

Hi -

Is it normal to pass an instantiated Database as a Function parameter? For
example, as
Function Update_PolicyTable (db as Database, intInvoicePolicyNo as integer)

The reason why I want to do it is that I instatiate the database in my main
loop, and
open all the recordsets there. Then I call a function that has this code

Dim db as Database
Dim rec as Recordset
Dim strSQL as String

strSQL = "SELECT * FROM tblPolicy WHERE polPolicyNo = " intInvoicePolicyNo

Set db = CurrentDb()
Set rec = db.OpenRecordset(strSQL, dbOpenDynaset)

This code is based on an example in my book that I want to modify.
I want to use strSQL, thus I need to dim the rec.
But do I need to dim the db also, or do I just pass it as a function
parameter?

(This is my first time using DAO and it is hard to get my head around doing
something beyond the examples in the book!)

Thanks!!

Joy
 
Joy,

It is absolutely fine to pass the database as a parameter (whether into sub
or function), but as long as you do not return anything from your function, I
sould suggest you turn it into a Sub.
 
Since you're passing the instantiated Database object as a parameter named
db, you do not want to declare an object with the same name inside your
function.
 
Hi Sergey and Doug -

Thanks for your advice. It was helpful to hear from you.

BTW You are right, Sergey, it is a Sub, not a Function.
Too much on my plate ))

Joy.
 
Back
Top