jkfeagle
Codus Confusious
- Local time
- Today, 03:39
- Joined
- Aug 22, 2002
- Messages
- 166
I have created a Medical Leave Case Management db and I am trying to have the db assign a case number automatically. The case could have a U1 or U2 prefix depending on which factory it pertains to and that will be based on a field on the main form (frmPersonalEntry). The case number will be shown on a subform (frmMedicalHistory). The case number is to be in the format U12002001. Where 2002 is obviously the year and 001 is an incrementing counter. Below is the code I am using but there are some issues with it that I can’t seem to figure out. First, I had not considered how to get it to differentiate between plants so that it increments each plants cases based on the previous one to that plant rather than between the two but when I look at it, can’t figure out a good way to do it. Secondly, the subform has buttons that allow the user to step through the cases for an individual as well as bring up a new record. However, when new record is selected, the case number comes up 0 instead of assigning a new case number. Can anyone help here?
Private Sub Form_Current()
Dim intYearDiff As Integer
intYearDiff = (Format(Date, "yyyy") - (Mid((DMax("[CaseNum]", "tblMedicalHistory")), 4, 4)))
If Forms![frmPersonalEntry]![frmMedicalHistory].Form.NewRecord Then
Select Case intYearDiff
Case 0
Forms![frmPersonalEntry]![frmMedicalHistory].Form![CaseNum] = Me.Plant & Mid((DMax("[CaseNum]", "tblMedicalHistory")), 4, 7) + 1
Case 1
Forms![frmPersonalEntry]![frmMedicalHistory].Form![CaseNum] = Me.Plant & Format(Date, "yyyy") & "001"
End Select
End If
End Sub
For the new record selection sub, the above code is entered after (Obviously without the same Sub header):
DoCmd.GoToRecord , , acNext
Private Sub Form_Current()
Dim intYearDiff As Integer
intYearDiff = (Format(Date, "yyyy") - (Mid((DMax("[CaseNum]", "tblMedicalHistory")), 4, 4)))
If Forms![frmPersonalEntry]![frmMedicalHistory].Form.NewRecord Then
Select Case intYearDiff
Case 0
Forms![frmPersonalEntry]![frmMedicalHistory].Form![CaseNum] = Me.Plant & Mid((DMax("[CaseNum]", "tblMedicalHistory")), 4, 7) + 1
Case 1
Forms![frmPersonalEntry]![frmMedicalHistory].Form![CaseNum] = Me.Plant & Format(Date, "yyyy") & "001"
End Select
End If
End Sub
For the new record selection sub, the above code is entered after (Obviously without the same Sub header):
DoCmd.GoToRecord , , acNext