G
Guest
Not sure where to post this. I have a database for making occasional
reports. The first report of this year is numbered RPT-05-01, the second
RPT-05-02, etc. My table (tblReport) contains fields for RPT_Number (such as
05-01) and RPT_Sequence (the last two digits of RPT_Number). A form (frmRPT)
is based on the table. I have placed the following code into the form's On
Current event:
If IsNull(Me.RPT_Sequence) Then
Me.RPT_Sequence = Nz(DMax("RPT_Sequence", "tblRPT"), 0) + 1
End If
If IsNull(Me.RPT_Number) Then
Me.RPT_Number = Format(Date, "yy") & "-" & _
Format(Me.RPT_Sequence, "00")
Else: Me.txtRPT_Number.Locked = True
End If
txtRPT_Number is the text box bound to RPT_Number. People can't change the
number after the record is created.
The above code assigns 05-01, 05-02, and so forth in the proper sequence,
and the number is retained when returning to the record, but of course it
will not restart at 06-01 next year. How can I assign the correct number at
the start of next year? In general is there a better way of assigning the
number, or are there any potential problems with the approach beyond what I
have mentioned?
reports. The first report of this year is numbered RPT-05-01, the second
RPT-05-02, etc. My table (tblReport) contains fields for RPT_Number (such as
05-01) and RPT_Sequence (the last two digits of RPT_Number). A form (frmRPT)
is based on the table. I have placed the following code into the form's On
Current event:
If IsNull(Me.RPT_Sequence) Then
Me.RPT_Sequence = Nz(DMax("RPT_Sequence", "tblRPT"), 0) + 1
End If
If IsNull(Me.RPT_Number) Then
Me.RPT_Number = Format(Date, "yy") & "-" & _
Format(Me.RPT_Sequence, "00")
Else: Me.txtRPT_Number.Locked = True
End If
txtRPT_Number is the text box bound to RPT_Number. People can't change the
number after the record is created.
The above code assigns 05-01, 05-02, and so forth in the proper sequence,
and the number is retained when returning to the record, but of course it
will not restart at 06-01 next year. How can I assign the correct number at
the start of next year? In general is there a better way of assigning the
number, or are there any potential problems with the approach beyond what I
have mentioned?