AutoNuber with date

amna77

Active Member
Joined
May 9, 2002
Messages
251
Hi, actually i am trying to create autonumber. the thing is with every day I want autonumber to start from one. for example if they enter 10 records per day then next day autonumber should start from 1 again.
any help please
thanks in advance
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Here is a snippet from a site that I no longer have the address for :(
Something else that seems to be popular is to try and create and primary key field that uses the date in conjunction with an autonumber, for example 010120010001 might be the first record that was created on 1 Jan 2001, whilst 050220010015 would be the fifteenth record created on 5 Feb 2001. This is a very bad idea - the idea of relational databases is to store one piece of information in each field. If you wanted to do something like this, you would need to modify the code above slightly, and add a date field to the table:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me!UniqueFieldName = Nz(DMax("[UniqueFieldName]", "[tblUnique]", "[DateField]=Date()"), 0) + 1
Me!DateField = Date
End Sub

You can then create a primary key for the table that is based on both the DateField and UniqueFieldName by selecting them both in the design view of the table by using the Control key and then clicking on the Primary Key symbol. You will then have a number that increments each day, and resets itself the next day.


HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,810
Messages
6,162,108
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top