
Passing parameters to a DMax function
This involves writing a function in Access 2.0
I have a database with multiple tables. Each table records a type of
accounting journal entry. Each table has a VoucherNumber field, which
has a name related to that account and each table has a related data
entry form. For example:
Table Voucher Number Field Data Entry Form
==== ================ ============
tbl_A VNF_A frm_A
tbl_B VNF_B frm_B
tbl_C VNF_C frm_C
I need to increment each voucher number when I enter a record. To do
this I have written a form level event procedure like this:
VNF_A = DMax("VNF_A", "tbl_A") + 1
(This is a simplification. The real code also has to take into account
the Fiscal Year and other things.)
The problem:
I have over 15 tables. Instead of repeating the code as an event
procedure in each form, I would like to write a module function that I
could call from each form.
However, I have limited experience/understanding in writing code. The
problem I am stuck on is how do I pass the field and table name to the
DMax command?
Number 1 - Is it even possible to use a code like,
Function VoucherNum (VNF)
Dim Field as Name of the Current VNF file
Dim Table as Name of the current source table
VoucherNumber = DMax("Field", "Table") + 1
Number 2 - If it is possible to substitute variables for specific names
in the DMax command, how to I pass the value of the appropriate VNF
field name and table name to those variables?
I have tried to use the Sourcefield and Sourcetable properties, but I
just don't get it. I have also used the DejaNews to try to find an
answer but no luck there.
Any help would be greatly appreciated.
My Newsgroup reader is pretty limited, so please respond via e-mail as
well as posting to the group.
Thank you
Dawson Lewis