Passing parameters to a DMax function 
Author Message
 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



Fri, 26 Nov 1999 03:00:00 GMT  
 Passing parameters to a DMax function

Try this code:

Function VoucherNum(pstrVoucherLetter) As Long

VoucherNum=DMax("tbl_"&pstrVoucherLetter, "VNF_" &pstrVoucherLetter)+1

End Function

You just pass in the letter of the voucher:

NewVoucherNum=VoucherNum("A")

And it gives you the new number for that voucher's table.

Forgive me if I am wrong, but your problem and its solution seem so
simple.  I may have missed your point completely.

Jawed
(-: Some kind of shark joke :-)



Thu, 02 Dec 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DMax and DMin functions

2. I'm trying to use 2 conditions with variables in a DMax function

3. dmax function

4. Using DMAX function in Visual Basic

5. DMax-function

6. Undefined function 'DMax' in expression

7. Question on passing array parameters to VB.NET Sub/Function

8. Passing a form as a parameter into function

9. Passing parameter to a library function...

10. Passing parameters from VB to a DLL function

11. pass object parameter to user control function

12. Passing a function in parameter

 

 
Powered by phpBB® Forum Software