Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    NJ, USA
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Incremental numbers (Access 03)

    I thought I had this solved. But I just found one problem. How do I get this to restart the right side to drop to 000 and start over. I.E. this year may be 04-152 but the first record for next year should be 05-001. I would appreciate any and all help. Thanks. Fay


    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strMax As String
    Dim lngNewNum As Long
    If Me.NewRecord = True Then
    strMax = Nz(DMax("IncidentID", "tblIncidents"), Format(Date, "yy") & "-000")
    lngNewNum = CLng(Right(strMax, 3)) + 1
    Me.IncidentID = Format(Date, "yy") & "-" & Format(lngNewNum, "000")
    End If

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Incremental numbers (Access 03)

    Replace

    <code>DMax("IncidentID", "tblIncidents")</code>

    by

    <code>DMax("IncidentID", "tblIncidents", "IncidentID Like " & Chr(34) & Format(Date, "yy") & "*" & Chr(34))</code>

    This restricts the DMax to IncidentID's for the current year; if not found, the Nz function will cause yy-000 to be returned.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    NJ, USA
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Incremental numbers (Access 03)

    Thanks Hans. It works great. I appreciate the help. Fay

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •