Good Day Dan,
Ok, I am going to give you exactly what I have in my test database:
tblorders
fields: ordernumber --> Datatype - number, Long Integer, decimal
places 0, default value 0, required - no , indexed -- no.
ordertype --> text, size 50, required - no, allowzero
length no, indexed no, unicode comp. - no,
frmorders: with fields:
ordernumber
ordertype --
cboordertype - Values "Custom", "Program", and "Stock" -- when the
user selects the order type, it is then saved to the field ordertype
cboordertype -- > code:
Code begin:
Private Sub cboordertype_AfterUpdate()
Dim lngOrderNumber As Long
lngOrderNumber = DMax("[ordernumber]", "tblorders", "ordertype = '" &
Me.cboordertype & "'") + 1
End Sub
Code End:
When I choose my option under my cboordertype, I am getting a runtime error
94, Invalid use of Null.
then when I click debug:
the following code is highlighted:
lngOrderNumber = DMax("[ordernumber]", "tblorders", "ordertype = '" &
Me.cboordertype & "'") + 1
Thanks,
Brook
Dan Artuso said:
Hi,
From the info in your post, I would say to put the code in the cboordertype AfterUpdate event.
No, it should definitely not be an autonumber.
I can only guess at how you want it to work, so, post more info.
Did the code fail? If so, what line?
I'm also assuming that each ordertype is treated seperately as far as order numbers go.
Is that correct?
The code I gave you places the new number in a variable, you have to do something with that.
--
HTH
-------
Dan Artuso, MVP
Brook said:
hello... I have tried your suggested code, but was unable to get it to work
the way that I would like..
Should my ordernumber in my tblorders be an "Autonumber"?
Do I need to add the code to the afterupdate?
Thanks,
Brook
Brook said:
Thank you very much Dan,
I am going to try this and see how it goes... I will post a response one
way or another.
Brook
:
Hi,
Something like this maybe?
dim lngOrderNumber as Long
lngOrderNumber = DMax("[ordernumber]", "tblorders", "ordertype = '" & Me.cboordertype & "'") + 1
--
HTH
-------
Dan Artuso, MVP
Good Day,
I have have a form (frmneworders) that is based on my tblorders. The fields
are ordernumber, ordertype(based on cboordertype) for Custom, Program, or
Sample, and orderdetails.
What I want to set up is this: When the user selects a new order, they will
choose the ordertype form the cboordertype, and after that ordertype is
selected I need to know how to create the code to lookup the DMAX for the
ordernumber and add 1 too it, to create a sequential ordering system for each
type of order.
If anyone has any ideas... tips please pass them along...
Thanks in advance..
Brook