I need to be able to allocate serial numbers to a field within a table. The serial number is made up of 3 parts e.g
"CPM2" "Medic1" "00012 = CPM2Medic10001.
The 1st part will always be CPM2, the 2nd part could be one of 4 values e.g Medic1, Medic2, Medic3, Medic4 and the 3rd part will be the next number in the sequence e.g 0001, 0002 etc. The 3 parts joined together will always be unique. Examples would include CPM2Medic10001, CPM2Medic10002, CPM2Medic20001, CPM2Medic30001 etc.
The code I have written is as follows:
Function AllocateSerNumb()
'THE FOLLOWING CODE IS SUPPOSED TO CHECK FOR MATCING serial numbers
'AND IF NO MATCH ALLOCATE A NEW serial number!!
Dim strPT1, strPT2, strIniSerNum, strSerNum As String
Dim intPT3 As Integer
Dim rstSurvData As Recordset
Dim dbsCDb As Database
strPT1 = "CPM2" 'will always be this
strPT2 = Forms![frmSatSurvData]![cboSection] 'could be Medic1, Medic2, Medic3, Medic4
intPT3 = Format(1, "0000" 'must be in this format
strIniSerNum = strPT1 & strPT2 & intPT3 'e.g. CPM2Medic10001
Set rstSurvData = CurrentDb.OpenRecordset("tblSatSurvData", dbOpenDynaset)
Set dbsCDb = CurrentDb()
'check to see if value exists in recordset
rstSurvData.FindFirst "txtSerialNo = '" & strIniSerNum & "'"
Do Until rstSurvData.NoMatch
intPT3 = intPT3 + 1
strIniSerNum = strPT1 & strPT2 & intPT3
Loop
strSerNum = strIniSerNum
MsgBox strSerNum
rstSurvData.Close
Set dbsCDb = Nothing
End Function
Am I barking up the wrong tree! Is there an easier way of doing it etc
Thanks for any help
Glen
"CPM2" "Medic1" "00012 = CPM2Medic10001.
The 1st part will always be CPM2, the 2nd part could be one of 4 values e.g Medic1, Medic2, Medic3, Medic4 and the 3rd part will be the next number in the sequence e.g 0001, 0002 etc. The 3 parts joined together will always be unique. Examples would include CPM2Medic10001, CPM2Medic10002, CPM2Medic20001, CPM2Medic30001 etc.
The code I have written is as follows:
Function AllocateSerNumb()
'THE FOLLOWING CODE IS SUPPOSED TO CHECK FOR MATCING serial numbers
'AND IF NO MATCH ALLOCATE A NEW serial number!!
Dim strPT1, strPT2, strIniSerNum, strSerNum As String
Dim intPT3 As Integer
Dim rstSurvData As Recordset
Dim dbsCDb As Database
strPT1 = "CPM2" 'will always be this
strPT2 = Forms![frmSatSurvData]![cboSection] 'could be Medic1, Medic2, Medic3, Medic4
intPT3 = Format(1, "0000" 'must be in this format
strIniSerNum = strPT1 & strPT2 & intPT3 'e.g. CPM2Medic10001
Set rstSurvData = CurrentDb.OpenRecordset("tblSatSurvData", dbOpenDynaset)
Set dbsCDb = CurrentDb()
'check to see if value exists in recordset
rstSurvData.FindFirst "txtSerialNo = '" & strIniSerNum & "'"
Do Until rstSurvData.NoMatch
intPT3 = intPT3 + 1
strIniSerNum = strPT1 & strPT2 & intPT3
Loop
strSerNum = strIniSerNum
MsgBox strSerNum
rstSurvData.Close
Set dbsCDb = Nothing
End Function
Am I barking up the wrong tree! Is there an easier way of doing it etc
Thanks for any help
Glen