E
ecsalbil
I have a form in which users will enter the document type (selected from a
combo box) and the initiation date (only the year is necessary but right now
the field is formatted as a general date). Based off of these two things I
need to assign a sequential number that for a record ID that begins at 1 for
each calendar year. My code right now is:
Private Sub InitiationDate_AfterUpdate()
Dim strCriteria As String
If Not IsNull(Me.ParentType) Then
strCriteria = [ParentType] = """ & Me.ParentType & """ & _
" And [InitiationDate] = #" & _
Format(Me.InitiationDate, "mm/dd/yyyy") & "#"
Me.ParentID = Nz(DMax("[ParentID]", "tbl_Parent", strCriteria), 0) + 1
End If
End Sub
Private Sub ParentType_AfterUpdate()
If Not IsNull(Me.InitiationDate) Then
strCriteria = [ParentType] = """ & Me.ParentType & """ & _
" And [InitiationDate] = #" & _
Format(Me.InitiationDate, "mm/dd/yyyy") & "#"
Me.ParentID = Nz(DMax("[ParentID]", "tbl_Parent", strCriteria), 0) + 1
End If
End Sub
Right now this is giving every record the number 1 and not increasing for the
second record of that type created for that calendar year. How do I get the
ID number assigned using the combination of the two fields.
Also, only one user will be in this database at a time to enter data (all
others would just be viewing) so duplicates aren't a concern at this time.
Thanks!
combo box) and the initiation date (only the year is necessary but right now
the field is formatted as a general date). Based off of these two things I
need to assign a sequential number that for a record ID that begins at 1 for
each calendar year. My code right now is:
Private Sub InitiationDate_AfterUpdate()
Dim strCriteria As String
If Not IsNull(Me.ParentType) Then
strCriteria = [ParentType] = """ & Me.ParentType & """ & _
" And [InitiationDate] = #" & _
Format(Me.InitiationDate, "mm/dd/yyyy") & "#"
Me.ParentID = Nz(DMax("[ParentID]", "tbl_Parent", strCriteria), 0) + 1
End If
End Sub
Private Sub ParentType_AfterUpdate()
If Not IsNull(Me.InitiationDate) Then
strCriteria = [ParentType] = """ & Me.ParentType & """ & _
" And [InitiationDate] = #" & _
Format(Me.InitiationDate, "mm/dd/yyyy") & "#"
Me.ParentID = Nz(DMax("[ParentID]", "tbl_Parent", strCriteria), 0) + 1
End If
End Sub
Right now this is giving every record the number 1 and not increasing for the
second record of that type created for that calendar year. How do I get the
ID number assigned using the combination of the two fields.
Also, only one user will be in this database at a time to enter data (all
others would just be viewing) so duplicates aren't a concern at this time.
Thanks!