Add 1 to Work Order #

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a command button in a form that creates a new Work Order. I would
like it to add 1 to the highest number in the table, i.e., our Work Orders
are numbered W-100, W-101, etc. I have tried placing the following code in
the BeforeUpdate event procedure, but nothing happens when I use the command
button. Does the DMax() code have to be placed within the command button
code? Also, does the "#" sign in my table/field names have an affect on the
codes?

If IsNull(Me![tblwoWorkOrder#]) Then
Me![tblwoWorkOrder#] = Nz(DMax("[tblwoWorkOrder#]", "tblWorkOrder#"), 0)
+ 1
End If

Thanks!
 
hi,
W-101 is not a number. it's text and you cannot add 1 to
it. that goes against computer logic.
you will have to seperate the w- from the 101 to do what
you want

SELECT "W-" & Right(Max([tblwoWorkOrder#]),3)+1 AS WONum
FROM tblWorkOrder;

Not sure if i got your table and field names right.
you can pop the results of the query into your text box.
-----Original Message-----
I have a command button in a form that creates a new Work Order. I would
like it to add 1 to the highest number in the table, i.e., our Work Orders
are numbered W-100, W-101, etc. I have tried placing the following code in
the BeforeUpdate event procedure, but nothing happens when I use the command
button. Does the DMax() code have to be placed within the command button
code? Also, does the "#" sign in my table/field names have an affect on the
codes?

If IsNull(Me![tblwoWorkOrder#]) Then
Me![tblwoWorkOrder#] = Nz(DMax
("[tblwoWorkOrder#]", "tblWorkOrder#"), 0)
 
Thank you for the reply, but where do I place this code so that when I click
the "Create New Work Order" button, the new sequential number is placed in
the field.

hi,
W-101 is not a number. it's text and you cannot add 1 to
it. that goes against computer logic.
you will have to seperate the w- from the 101 to do what
you want

SELECT "W-" & Right(Max([tblwoWorkOrder#]),3)+1 AS WONum
FROM tblWorkOrder;

Not sure if i got your table and field names right.
you can pop the results of the query into your text box.
-----Original Message-----
I have a command button in a form that creates a new Work Order. I would
like it to add 1 to the highest number in the table, i.e., our Work Orders
are numbered W-100, W-101, etc. I have tried placing the following code in
the BeforeUpdate event procedure, but nothing happens when I use the command
button. Does the DMax() code have to be placed within the command button
code? Also, does the "#" sign in my table/field names have an affect on the
codes?

If IsNull(Me![tblwoWorkOrder#]) Then
Me![tblwoWorkOrder#] = Nz(DMax
("[tblwoWorkOrder#]", "tblWorkOrder#"), 0)
+ 1
End If

Thanks!
.
 
Back
Top