Gasman
Enthusiastic Amateur
- Local time
- Today, 19:37
- Joined
- Sep 21, 2011
- Messages
- 17,527
Ok,Thanks Gasman, I understand what you are saying now and I like the idea. I am still learning vba so unfortunately I wouldn't know where to start with writing the code.
You would have a numeric field in the table for last used suffix (but in numeric form) along with a field for the order number. Let's call that suffix field DeliverySuffix
On the the very first delivery there will be no value so DMAX() would return Null, so we would use the NZ() function to catch that.
Code:
iNextSuffix = NZ(DMAX("DeliverySuffix","DeliveryTable","OrderNo = " & Me.OrderNo),0) + 1
Code:
txtDeliveryCode = Format(Me.OrderNo,"0000") & CHR(64 + iNextSuffix)
which would produce something like 1234A and the table would now have a value of 1 in that record along with the OrderNo
Then the next time, you would do the same, but this time it would find the record an return that 1 value and you would add 1 to it and have 2 as a value and do the same thing.?
I would create a function that returns the new delivery code by passing the required code to that function. Then it would be
txtDeliveryCode = NextDeliverySuffix(Me.OrderNo)
You might not have the actual OrderNo, but the autonumber FK for that order, but the process would be the same.?
HTH