Richard
asked on
access requery/refresh/dirty
I have a subform.
The form creates invoices and gives a unique conseq number to a field in that form called UniqueInvoiceID by virtue of the D Max function.
There is a filed called DateOfInvoice with a date picker.
What I need is when the date is entered the UniqueInvoice ID is puled thru as this only seems to happen when the user (multi-user) leaves the form.
It needs to refresh/requery/calculate and enter the Dmax funnction when the date picker picks a date.
Ideas?
The form creates invoices and gives a unique conseq number to a field in that form called UniqueInvoiceID by virtue of the D Max function.
There is a filed called DateOfInvoice with a date picker.
What I need is when the date is entered the UniqueInvoice ID is puled thru as this only seems to happen when the user (multi-user) leaves the form.
It needs to refresh/requery/calculate and enter the Dmax funnction when the date picker picks a date.
Ideas?
ASKER
Interesting as I have calculated it in the Unique ID field.
I have been struggling for some error code ----could you think of any?
Thanks,.
I have been struggling for some error code ----could you think of any?
Thanks,.
This would be assuming that the UniqueInvoiceID is indexed to allow no duplicates and that there are no other required fields, it's not the most elegant way, and we should probably add some maximum number of tries to ensure it never goes into and endless loop, but it should work :
Private sub DateOfInvoice_AfterUpdate
On Error GoTo Err_DateOfInvoice_AfterUpdate
If nz(UniqueInvoiceID,"") = "" Then
GenerateNewID:
Me.UniqueInvoiceID = DMAX("UniqueInvoiceID","TableName")
Docmd.RunCommand acCmdSaveRecord
End If
Exit_DateOfInvoice_AfterUpdate:
Exit sub
Err_DateOfInvoice_AfterUpdate:
If err.Number = 3022 Then 'Error returned when the value already exists
Resume GenerateNewID
else
msgbox err.number & " - " & err.description
Resume Exit_DateOfInvoice_AfterUpdate
end if
End sub
ASKER
Thanks, looks promising. Will test and return.
Oops, just noticed I didn't add a +1 to the DMax in that code example, be sure to add it or it's a definite endless loop hehe :
DMAX("UniqueInvoiceID","Ta bleName")+ 1
DMAX("UniqueInvoiceID","Ta
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
fyed,
Ive got that thanks. It works.
I was just looking for a way to update the new DMAX filed without logging out.
Ive got that thanks. It works.
I was just looking for a way to update the new DMAX filed without logging out.
I would calculate it in the after_update event of the date field, then issue a "docmd.runcommand accmdsaverecord" to ensure it is saved in the database immediately. Be sure to add some error checking for duplicates anyways, because it could happen that another user adds a record between the time you assigne the value to the invoice ID and the save record.
Hope it helps,
Mike