GaryCanuck
Technical User
Hi All,
I'm currently running Access 2007. I have a field called Close# that I would like to increment from the previous highest Close#. There are a number of complicating factors however.
First, the tables are shared with another program and the field is a text field. So it can't simply be changed to autonumber. Second, the format of the number has changed over the years and includes the letter "C". It has been #C##, ##C## and most recently #####C. The most recent numbers are 5 digits so if the C were removed or if the number to the left of the C were returned by the code then it would successfully return the most recent number.
I have gotten the following code to return the highest number, remove the "C", and increment it by one. The issue is that it is only returning the highest number to the right of the "C".
Does anyone have suggestions on how to alter my code or even an alternate way of doing this? I greatly appreciate any help or suggestions.
Here's the code. It's running on the double click event of a form text field.
I'm currently running Access 2007. I have a field called Close# that I would like to increment from the previous highest Close#. There are a number of complicating factors however.
First, the tables are shared with another program and the field is a text field. So it can't simply be changed to autonumber. Second, the format of the number has changed over the years and includes the letter "C". It has been #C##, ##C## and most recently #####C. The most recent numbers are 5 digits so if the C were removed or if the number to the left of the C were returned by the code then it would successfully return the most recent number.
I have gotten the following code to return the highest number, remove the "C", and increment it by one. The issue is that it is only returning the highest number to the right of the "C".
Does anyone have suggestions on how to alter my code or even an alternate way of doing this? I greatly appreciate any help or suggestions.
Here's the code. It's running on the double click event of a form text field.
Code:
Private Sub CLOSE__DblClick(Cancel As Integer)
Dim strMaxKey As String
strMaxKey = DMax("[Close#]", "File")
'MsgBox (strMaxKey)
strMaxKey = Replace(strMaxKey, "C", "")
'MsgBox (strMaxKey)
NextKey = Format(Val(Right(strMaxKey, 5)) + 1, "00000")
'MsgBox (NextKey)
End Sub