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 15718
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)>
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
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() .
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
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 :-(
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: 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...
|
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...
|
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: 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...
|
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: 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...
| |