473,465 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom made Autonumber to show today's date

3 New Member
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 15732
missinglinq
3,532 Recognized Expert Specialist
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 Recognized Expert Expert
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
hildemoseby
3 New Member
Thank you, I combined both of your ideas and think I got something useful out of it :)
H.
Aug 21 '07 #4
hildemoseby
3 New Member
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
geuvara
2 New Member
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
geuvara
2 New Member
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 New Member
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 Recognized Expert Moderator MVP
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 Recognized Expert New Member
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 Recognized Expert Moderator MVP
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.