Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DMax function (Access 2000)

    Automatic increase of the invoice number

    I want to write a function that automatically increases the last number of the invoice with 1. The name of my form is FOrderInformation and the name of the control is PaymentID.I have been told to use the function DMax but i do not know how to use it.
    For example,if the last time the number of the paymentid has been 17,000, the next number to be 17001.
    I want to buld my code like that

    Public Function increment()
    increment = DMax(Forms!FOrderInformation!Paymentid, + 1)
    End Function
    and then to use this function in the OnOpen event of the form.

    Can somebdy explain me why my function doesnt work?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DMax function (Access 2000)

    Public Function increment()
    increment = DMax("NameOfField",NameOfTable")+ 1
    End Function
    Dmax is use to find the maximum of a field in a table. Not on a form.
    In the form use for the textbox PaymentID
    =increment().
    You could also work without the function and enter in PaymentID:
    =DMax("NameOfField",NameOfTable")+ 1
    Francois

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DMax function (Access 2000)

    I recon you missed out a

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DMax function (Access 2000)

    I admit the typo.
    It must be Monday morning <img src=/S/doze.gif border=0 alt=doze width=15 height=15>
    Francois

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: DMax function (Access 2000)

    The problem with this approach is that if more than one user tries to get the dmax number at the same time you may end up with duplicate invoice numbers.
    You could be better off using a number specially defined in another table that the user reads the invoice number from this table, adds 1 to it and writes it back to the table then uses this updated number as the invoice number.
    HTH
    Pat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •