arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Today, 15:33
- Joined
- May 7, 2009
- Messages
- 20,746
create a function that will generate the 4-digit serial.
add code to the After Update event of the 2 combo (property and year):
private sub cboProperty_AfterUpdate()
Me!txtIncidentNumber = NewIncidentNumber(Me!cboProperty, Me!cboYear)
end sub
private cboYear_AfterUpdate()
Me!txtIncidentNumber = NewIncidentNumber(Me!cboProperty, Me!cboYear)
end if
paste to a Module:
add code to the After Update event of the 2 combo (property and year):
private sub cboProperty_AfterUpdate()
Me!txtIncidentNumber = NewIncidentNumber(Me!cboProperty, Me!cboYear)
end sub
private cboYear_AfterUpdate()
Me!txtIncidentNumber = NewIncidentNumber(Me!cboProperty, Me!cboYear)
end if
paste to a Module:
Code:
Public Function NewIncidentNumber(ByVal propCode As String, Optional ByVal Yr As Variant = -1) As String
'
' arnelgp
'
' NOTE!
'
' change TABLE_NAME and SEQN_FIELD to the name
' of your table an field.
'
Const TABLE_NAME As String = "sequence_table"
Const SEQN_FIELD As String = "sequence"
Dim strValue As String
If IsNull(Yr) Then Yr = Year(Date)
If Yr = -1 Then Yr = Year(Date) - 2000
If Yr > 2000 Then
Yr = Yr - 2000
End If
strValue = Nz(DMax("Left$(Right$([" & SEQN_FIELD & "],7),4)", _
"[" & TABLE_NAME & "]", "Right$([" & SEQN_FIELD & "], 2) = '" & Yr & "'"), "0")
NewIncidentNumber = propCode & "-" & Format$(Val(strValue) + 1, "0000") & "-" & Yr
End Function