473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Custom made Autonumber to show today's date

Hi,
I am designing a database for work and would like my autonumber to be of the following format:
yyyymmdd-001
yyyymmdd-002
yyyymmdd-003
So, the date the entry is made(today) dash an increasing number starting at 001 each new day.

Can someone tell me how that's done, or if it's even doable?

Cheers,
Hilde.
Aug 20 '07 #1
10 15718
missinglinq
3,532 Expert 2GB
The concept you're talking about is an incremental ID number. Don't call it an Autonumber. An Autonumber is a specific datatype in Access, it's a Long Integer and it's automatically generated by Access.

Here's the link for a Micro$oft tutorial on doing this very thing

http://office.microsoft.com/en-us/ac...550831033.aspx

The left half of your string can be generated with Format(date,"yyyymmdd"). The tutorial will show you how to generate the incrementing part.

Welcome to TheScripts!

Linq ;0)>
Aug 20 '07 #2
ADezii
8,834 Expert 8TB
Hi,
I am designing a database for work and would like my autonumber to be of the following format:
yyyymmdd-001
yyyymmdd-002
yyyymmdd-003
So, the date the entry is made(today) dash an increasing number starting at 001 each new day.

Can someone tell me how that's done, or if it's even doable?

Cheers,
Hilde.
Assumptions:
  1. Your Table Name is tblTest.
  2. Your specially formatted AutoNumber Field is called [ID] and it is the Primary Key.
  3. To produce the next AutoNumber in sequence with your specifications:
    Expand|Select|Wrap|Line Numbers
    1. NextAutoNum = Format$(Now(), "yyyymmdd") & "-" & Format$(Val(Right$(DLast("[ID]", "tblTest"),3))+1, "000")
  4. If the last [ID] value was 20070820-034, the next one will be:
    Expand|Select|Wrap|Line Numbers
    1. 20070820-035
Aug 20 '07 #3
Thank you, I combined both of your ideas and think I got something useful out of it :)
H.
Aug 21 '07 #4
Hi,
as I've never done this before, this is the code I ended up with using a code builder in a form (no autonumber).

Dim strMax As String
strMax = DMax("ID", "Register")
Me!HiddenCtl = Format$(Now(), "yyyymmdd") & "-" & Right(strMax, Len(strMax) - InStr(1, strMax, "-")) + 1

This works - sort of. What happens is that the date changes, but the number after the dash doesn't start at 1 again. So I get:
20070821-1
20070821-2
20070822-3
etc...
How can I get it to start over again????

Cheers
Aug 22 '07 #5
I did the same of "hildemoseby", and I have the same result, but I wonder if I can add characters before of the date and the number and the data appear like this

NSR-20100604-1
NSR-20100604-2

Any Help?

thanx
Jun 4 '10 #6
I did the code

Private Sub Name_AfterUpdate()
Dim strMax As Variant
strMax = DMax("fldcount", "tblcount")
Me!HiddenCtl = "NSR" & Format$(Now(), "yyyymmdd") & "-" & Right(strMax, Len(strMax) - InStr(1, strMax, "-")) + 1

End Sub

and I have the result

NSR20100604-1

but the problem now when the increment value reach "10" all increaments stops like this

NSR20100604-8
NSR20100604-9
NSR20100604-10
NSR20100604-10
NSR20100605-10
Jun 4 '10 #7
arbabreza
1 Bit
Expand|Select|Wrap|Line Numbers
  1. Me.ID = Format(Now(), "yyyymmdd") & "-" & Format(Val(Right(Nz(DLast("[ID]", "Table1"), 0), 3)) + 1, "000")
Dec 28 '20 #8
NeoPa
32,556 Expert Mod 16PB
That assumes the last entry - in the order Access presents you the data from that table - is also the most recent. Essentially you're code suffers from the same limitation that ADezii's does from way back in August 2007. In fact it looks pretty identical - even as far as using Now() instead of Date(). You're better off using DMax().
Dec 28 '20 #9
cactusdata
214 Expert 128KB
It takes a little more:
Expand|Select|Wrap|Line Numbers
  1. NextID = Format(Date, "yyyymmdd\-") & Right("00" & CStr(Val(Nz(DMax("[ID]", "tblTest", "[ID] Like '" & Format(Date, "yyyymmdd\*") & "'"))) + 1), 3)
Dec 29 '20 #10
NeoPa
32,556 Expert Mod 16PB
Yes. Well spotted. I did some work on this type of thing a while ago but lost many of my notes when my PC died earlier in the year :-(
Dec 29 '20 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Tony Williams | last post by:
I have a table called tblseries with a field NextNumber I also have a form called form1 based on table1 On the form is a control NNum which I've called NNumtxt with the following code in the...
5
by: ndn_24_7 | last post by:
Hello all, I'm designing a incident reporting program that allows our security department to record incidents. The problem i'm having is on a form, when ever a user is going to add a new...
5
by: Apple | last post by:
May anyone can teach me how to assign a autonumber, I want to create a number that is starting with year(auto change to year 2006) + autonumber (eg. 2005-0001, 2005-0002)
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
8
by: Radu | last post by:
Hi. I have an ASP control on my page: <asp:Calendar ID="calStart" ................ Etc </asp:Calendar> and I have a Custom Validator defined as <asp:CustomValidator
5
by: troy_lee | last post by:
I have a table that has a PK field with the following format: Dyymm123. So that, a typical number might look like this D0806270. The first character is literal and never changes. The next four...
6
by: =?Utf-8?B?QmVu?= | last post by:
All - I have VB2008. On the form I have a date picker and a text box. I put would like to display a date format in the form of "MM-DD-YYYY" or "MM-YYYY" I am new to vb2008, can you show me...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.