Solved SIMPLE RECORD NUMBER START FROM 01 EACH NEW MONTH (1 Viewer)

georg0307

Registered User.
Local time
Today, 05:42
Joined
Sep 11, 2014
Messages
91
Dear All,

I have a simple Access Data Base that records truck arrival.
I need a field that automatically give a sequential number to the new record (new truck arrival), 1,2,3,4..etc
And at arrival of the new Month, start again with 1,2,3,4..etc, without any user intervention.

Attached a draft of my DB.

Thanks in advance
Best regards
 

Attachments

  • CAMION.zip
    28.2 KB · Views: 94

Ranman256

Well-known member
Local time
Yesterday, 23:42
Joined
Apr 9, 2015
Messages
4,337
AutoNum field does this with no programming.
Sort on this field for that month and you have the order.
In a report ,use a cumulative count if you must have 1 as the start.

Zero programming.


QUOTE="georg0307, post: 1673109, member: 134244"]
Dear All,

I have a simple Access Data Base that records truck arrival.
I need a field that automatically give a sequential number to the new record (new truck arrival), 1,2,3,4..etc
And at arrival of the new Month, start again with 1,2,3,4..etc, without any user intervention.

Attached a draft of my DB.

Thanks in advance
Best regards
[/QUOTE]
 

ebs17

Well-known member
Local time
Today, 05:42
Joined
Feb 7, 2020
Messages
1,944
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
   If.MeNewrecord Then
      Me.txtNr = Nz(DMax("Nr", "AnyTable", _
             "Format(ArrivalDate, 'yyyymm') = '" & Format(Me.txtArrivalDate, "yyyymm") & "'"), 0) + 1
   End If
End Sub

Eberhard
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:42
Joined
May 7, 2009
Messages
19,233
add code to textbox, DATA, AfterUpdate event:
Code:
Option Compare Database
Option Explicit

Private Sub Data_AfterUpdate()
    Dim RS As DAO.Recordset
   
    If IsDate(Me.Data & "") Then
   
        Me.NR = Val(DMax("NR", "ARRIVI_CAMION", "Format([Data], 'yyyymm') = '" & Format(Me.Data, "yyyynn") & "'") & "") + 1
   
    End If
   
End Sub
 

georg0307

Registered User.
Local time
Today, 05:42
Joined
Sep 11, 2014
Messages
91
add code to textbox, DATA, AfterUpdate event:
Code:
Option Compare Database
Option Explicit

Private Sub Data_AfterUpdate()
    Dim RS As DAO.Recordset
  
    If IsDate(Me.Data & "") Then
  
        Me.NR = Val(DMax("NR", "ARRIVI_CAMION", "Format([Data], 'yyyymm') = '" & Format(Me.Data, "yyyynn") & "'") & "") + 1
  
    End If
  
End Sub
 

georg0307

Registered User.
Local time
Today, 05:42
Joined
Sep 11, 2014
Messages
91
Hi,

sorry but it doesn't increment number...

Thanks for prompt reply
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:42
Joined
May 7, 2009
Messages
19,233
my fault this need to be changed:

Format(Me.Data, "yyyynn")

to

Format(Me.Data, "yyyymm")
Code:
Private Sub Data_AfterUpdate()  
Dim RS As DAO.Recordset     
If IsDate(Me.Data & "") Then         
    Me.NR = Val(DMax("NR", "ARRIVI_CAMION", "Format([Data], 'yyyymm') = '" & Format(Me.Data, "yyyymm") & "'") & "") + 1     
End If 
End Sub
 

ebs17

Well-known member
Local time
Today, 05:42
Joined
Feb 7, 2020
Messages
1,944
@arnelgp:

What is the meaning of the recordset in the code?
If you can overwrite an existing number with an existing meaning, you leave a sequential numbering because gaps can arise.


@georg0307

We use one (=> 1) date field to determine the month. What do you use?
Your table structure has several and is probably to be corrected: Additional normalization step required?

Eberhard
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:42
Joined
May 7, 2009
Messages
19,233
the recordset is unused. should be removed.
 

Users who are viewing this thread

Top Bottom