Help with Dmax Funtion

disregard that last comment.

sorry yes
when a customer calls to make a booking and there are no active invoice ( already posted ) then this will create a new invoice but if there is an invoice waiting to be posted (active ) then this will simply add this booking to the current invoice?

thanks
 
Run it in the Current event of the form and test for NewRecord like this:
Code:
If Me.NewRecord Then
    ... other code given here ...
End If
 
I am using this now in the afterupdate field of invoicedetails.customerid text field
but still getting same message you must save first

am i still doing something wrong
i change the line

invMax = Nz(DMax("InvoiceNumber", "activeinvoices", "CustomerID = '" & Me.CustomerID & "'"), 0)

to

invMax = Nz(DMax("InvoiceNumber", "activeinvoices", "CustomerID = '" & me.Invoicedetails.CustomerID & "'"), 0)
 
I am using this now in the afterupdate field of invoicedetails.customerid text field
but still getting same message you must save first

am i still doing something wrong
i change the line

invMax = Nz(DMax("InvoiceNumber", "activeinvoices", "CustomerID = '" & Me.CustomerID & "'"), 0)

to

invMax = Nz(DMax("InvoiceNumber", "activeinvoices", "CustomerID = '" & me.Invoicedetails.CustomerID & "'"), 0)
You missed my last post.
 
Many thanks for your replys but there is still something slightly adrift

Could I possibly send you a copy of the database of where I am at upto now
this will show you more what i mean and you will get to what we are doing

Thanks
Simon
 
please find attached
if you read the form "read me " this will hopefully explain a little bit more

thanks
 

Attachments

Sorry, not the Current event. I was probably over multi-tasking :)

The After Update event of the CustomerID textbox:
Code:
    If Me.NewRecord Then
        Dim invMax As Long
        
        invMax = Nz(DMax("InvoiceNumber", "lookuplastinvoicenumber", "CustomerID = '" & Me.CustomerID & "'"), 0)
        
        If invMax <> 0 Then
            Me.Bookings_InvoiceNumber = invMax + 1
        Else
            Me.InvoiceDetails_InvoiceNumber = Nz(DMax("InvoiceNumber", "invoicedetails"), 0) + 1
        End If
    End If
 

Users who are viewing this thread

Back
Top Bottom