Finicky code

dcc15

New member
Local time
Today, 02:12
Joined
Nov 26, 2007
Messages
9
Hi all
I am having a problem with code I am using to build ID's (stored as text). I am using it in several Forms (a couple with cmdButtons and one "beforeInsert", I am just changing the "prefix", table and field/control names as required (the sequence number starts at 0001 at each month change).
The problem I am experiencing is the code seems to work fine for several sessions, but for reasons that are beyond me will suddenly (unexplainably) start returning only "0001"; I am perplexed and need some advise/help...
The only thing I see that is weird is the "Me.CaNum", the C & A are force to upper case, the other two forms I am using this code in are all forced lower case even though the table and controls are mixed (RmaNum is Me.rmanum),
I'm at a loss, any help would be appreciated.
Thanks,

Private Sub cmdIssCA_Click()
'-- Generates record ID

On Error GoTo MyErrorHandler

Dim strPref As String
Dim strYrMo As String
Dim strWhere As String
Dim strResult As String

strPref = "C"
strYrMo = Format(Date, "yymm")
strWhere = "[CaNum] Like """ & strPref & strYrMo & "*"""
strResult = Nz(DMax("[CaNum]", "CorrectiveActions", strWhere))

If IsNull(strResult) Then
Me.CaNum = strPref & strYrMo & "0001"
Else
Me.CaNum = Left(strResult, 4 + Len(strPref)) & _
Format(Val(Right(strResult, 4)) + 1, "0000")
End If

MyErrorHandlerExit:
Exit Sub

MyErrorHandler:
MsgBox "Error Description: " & Err.Description & " Error Number: " & Err.Number
Resume MyErrorHandlerExit

End Sub
 

Users who are viewing this thread

Back
Top Bottom