Expand|Select|Wrap|Line Numbers
- Private Sub Specimen_ID_GotFocus()
- 'Get the next Spec ID
- Dim NextSpecID As String
- Dim CurrSpecID As String
- 'Get the last 3 characters from the last specimen ID belonging to this project number
- CurrSpecID = Nz(Right(DMax("[Specimen ID]", "Spec", "[Project Number] = '" & Me.Project_Number & "'"), 3), 0)
- 'Increment the ID by 1
- NextSpecID = Nz(CurrSpecID, 0) + 1
- 'Add in zeros until it's 3 characters long
- Do Until Len(NextSpecID) = 3
- NextSpecID = "0" & NextSpecID
- Loop
- 'Build the next ID.
- NextSpecID = Format(Date, "yy") & "-" & Me.Project_Number & "-" & NextSpecID
- 'Now put it in the form
- Me.[Specimen ID] = NextSpecID
- End Sub
In this, 12 stands for the current year, 201213 stands for the project number, and 001 stands for the number of specimen id under that particular project number.
as i click on the next row under specimen id, it automatically generates next specimen id as 12-201213-002. The code used for the same is as stated above.
The problem is that i am not able to modify "Specimen ID" as 12-201213-001A and 12-201213-001B and so on. If i try to do it, it shows a RUN TIME ERROR "13".
I feel that i will have to use the If-Then-Else loop, but i am not able to frame it properly as i am a novice in coding. Please help me with it.