you don't need to cycle through all the records and count them to do what you're asking. If you are stuck with this system of number things I would suggest using the DMAX function
secondly, don't delete your data, you can simply add a 'active/inactive' flag and show/report only the items that are active. This prevents you from losing historical data and possibly orphaning data.
Code:
tblTest
ID_NO CustCode
ABCD-1 ABCD
ABCD-2 ABCD
ABCD-4 ABCD
ABCD-5 ABCD
EFGH-1 EFGH
So let's say this is your table.
I am assuming you have a form where you are selecting the customer so you can recall that value, let's call that form frmTest, and on that form there is a field [CustCode]
you could have an 'add new' button that would have code like:
Code:
dim sMaxID
sMaxID = dmax("[ID_NO]", "tblTest", "[CustCode] = '" & forms!frmTest!CustCode & "'")
'If you have customer ABCD chosen you will get the value ABCD-5 with this dmax statement
sMaxID = left([sMaxID], instr(sMaxID,"-")) & Right([sMaxID], len([sMaxID])-(instrev([sMaxID], "-") +1))
then you can populate the 'new' record with the 'new' sMaxID, just make sure you debug.print smaxID while you test your code.