CODE1
Private Sub File_TypeA_AfterUpdate()
Dim FileType As String
Dim MaxVal As String
FileType = Me!FileIDType_A
Select Case FileType
Case "Correspondence"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "C" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case "Document"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "D" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case "Env Assessment"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "EA" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case "Map/Graphic"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "M" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case "Public/Agency Involvement"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "P" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case "Reference Library"
MaxVal = DMax("[TempDocID]", "T_DocList", "[In_PR_AR]=2")
Me!TempDocID = "R" & Format(Val(Right(MaxVal, 5)) + 1, "00000")
Case Else
Cancel = True
End Select
End Sub
CODE2
Private Sub File_TypeA_AfterUpdate()
Dim DB As DAO.Database
Dim rst As DAO.Recordset
Dim lngCntr As Long
Dim intRetry As Integer
Dim intNum As Integer, intA As Integer, intB As Integer
Dim strANum As String
On Error GoTo ErrorAlphaNumGenerate
If IsNull(File_TypeA) Then
Cancel = True
Else
Set DB = CurrentDb()
Set rst = DB.OpenRecordset("T_Counter ", DB_OPEN_DYNASET)
rst.MoveFirst
rst.Edit
rst!Value = rst!Value + 1
rst.Update
lngCntr = CLng(rst!Value) - 1
intNum = lngCntr Mod 1000
intA = (lngCntr \ 1000) Mod 26
intB = (lngCntr \ 1000) \ 26
strANum = Chr$(intB + 65) & Chr$(intA + 65) & Format$(intNum, "0000")
AlphaNumGenerate = strANum
Me!TempDocID = strANum
ExitAlphaNumGenerate:
Exit Sub
ErrorAlphaNumGenerate:
If Err = 3188 Then
intRetry = intRetry + 1
If intRetry < 100 Then
Resume
Else
MsgBox Error$, 48, "Another user editing this number"
Resume ExitAlphaNumGenerate
End If
Else
MsgBox Str$(Err) & " " & Error$, 48, "Problem Generating Number"
Resume ExitAlphaNumGenerate
End If
End If
End Sub
|