B
BruceM
First, I know that my approach violates all sorts of rules. The trouble is
that I can't find another way to do this. I have not been able to find a
way to frame the question so that a groups search yields information that is
useful to my situation. So with the disclaimer that this approach is all
wrong according to normalization principles, it does at least produce the
desired result. I would like to know how I can accomplish this and still
maintain normalization rules.
The aim of this code is to assemble a number consisting of the department
code (one or two letters), the last two digits of the year, and an
incremented two-digit number (with a leading 0 as needed). For example:
D0701, D0702, AR0701, D0703. Actually, the number needs to appear as
D-07-01, AR-07-01, etc., but I expect I can figure out how to insert the
dashes for display purposes. Next year the number starts over at D0801, etc.
cboDept is an unbound combo box from which the user selects a department.
If I can find a way to do this without storing the two-digit year
redundantly I will need to store the department code in the field [DeptCode]
rather than pulling it from an unbound combo box.
This code is in the After Update event of cboDept. I realize that in a
multi-user environment I will need to make arrangements to guard against
duplication.
If Me.NewRecord Then
Dim strWhere As String, strDept As String, strYear As String
Dim varResult As Variant
strDept = Me.cboDept
strYear = Format(Me.RepDate, "yy")
strWhere = "[MyNumber] Like """ & strDept & strYear & "*"""
varResult = DMax("[MyNumber]", "tblMyTable", strWhere)
If IsNull(varResult) Then
Me.txtMyNumber = strDept & strYear & "01"
Else
Me.txtMyNumber = Left(varResult, Len(strDept) + 2) & _
Format(Val(Right(varResult, 2)) + 1, "00")
End If
End If
that I can't find another way to do this. I have not been able to find a
way to frame the question so that a groups search yields information that is
useful to my situation. So with the disclaimer that this approach is all
wrong according to normalization principles, it does at least produce the
desired result. I would like to know how I can accomplish this and still
maintain normalization rules.
The aim of this code is to assemble a number consisting of the department
code (one or two letters), the last two digits of the year, and an
incremented two-digit number (with a leading 0 as needed). For example:
D0701, D0702, AR0701, D0703. Actually, the number needs to appear as
D-07-01, AR-07-01, etc., but I expect I can figure out how to insert the
dashes for display purposes. Next year the number starts over at D0801, etc.
cboDept is an unbound combo box from which the user selects a department.
If I can find a way to do this without storing the two-digit year
redundantly I will need to store the department code in the field [DeptCode]
rather than pulling it from an unbound combo box.
This code is in the After Update event of cboDept. I realize that in a
multi-user environment I will need to make arrangements to guard against
duplication.
If Me.NewRecord Then
Dim strWhere As String, strDept As String, strYear As String
Dim varResult As Variant
strDept = Me.cboDept
strYear = Format(Me.RepDate, "yy")
strWhere = "[MyNumber] Like """ & strDept & strYear & "*"""
varResult = DMax("[MyNumber]", "tblMyTable", strWhere)
If IsNull(varResult) Then
Me.txtMyNumber = strDept & strYear & "01"
Else
Me.txtMyNumber = Left(varResult, Len(strDept) + 2) & _
Format(Val(Right(varResult, 2)) + 1, "00")
End If
End If