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.
10 15732
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)> 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:- Your Table Name is tblTest.
- Your specially formatted AutoNumber Field is called [ID] and it is the Primary Key.
- To produce the next AutoNumber in sequence with your specifications:
- NextAutoNum = Format$(Now(), "yyyymmdd") & "-" & Format$(Val(Right$(DLast("[ID]", "tblTest"),3))+1, "000")
- If the last [ID] value was 20070820-034, the next one will be:
Thank you, I combined both of your ideas and think I got something useful out of it :)
H.
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
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
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 - Me.ID = Format(Now(), "yyyymmdd") & "-" & Format(Val(Right(Nz(DLast("[ID]", "Table1"), 0), 3)) + 1, "000")
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() .
It takes a little more: - NextID = Format(Date, "yyyymmdd\-") & Right("00" & CStr(Val(Nz(DMax("[ID]", "tblTest", "[ID] Like '" & Format(Date, "yyyymmdd\*") & "'"))) + 1), 3)
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 :-(
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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)
|
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...
|
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......
|
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.
...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |