Wrox Programmer Forums
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 28th, 2008, 02:00 PM
Registered User
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default AUTO FORMAT field

Hi Friends...

I have a problem... I create a field named member_ID(primary key) in a table called TMEMBER. The field format is AAAA-08-00000001.
"AAAA" - fixed alphabet.
"08" - year (change when comes to a new year)
"00000001" - add 1 to each new record. If record no 10 -> "00000010".

The problem is that I do not know how to make the member_ID field automatically appeared and calculated on each new record. Let say, I create a new record (record no.2), previously record no.1...
Previously, the member_id is "AAAA-08-00000001", when create new record, the member_ID field should automatically appeared "AAAA-08-00000002" but it didn't. That includes the year "08", if current year is 2009, the middle digit should appear "09".

Need help from expert friends in this forum...

Thanks & regards,
Old March 28th, 2008, 07:36 AM
Authorized User
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts

This shouldn't be to difficult to resolve. There are a couple of ways to do it, if data is entered via a form for a new record then may i suggest the best way would be generate this via code. So the primary ket in your table should be a text field which you can leave as the primary ID if you wish.
If you need some help with this code let me know and i will post an example for you. Just advised how this ID is generated, via single form, continuous form, datasheet


Old April 4th, 2008, 07:24 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG

Hmmm... if the "AAAA" part is always that and the only thing that changes are the year and number, consider this. How about spliting the ID field into just two fields: the year (say, intYear; better to have four digits to be Y2K compliant, remember that?), and a long integer (say, lngID). Then for forms and reports you simply DISPLAY the full ID using concatenation of "AAAA" & "-" & intYear & "-" & Format(lngID, "00000000").

To add one to the ID would be simply

lngID = Nz(DMax("[lngID]" , "TMEMBER", "[intYear] = " & Year(Date())), 0) + 1

That is, if the year is automatically calculated from the current year. If there are no members for the year 2009 then the Nz() function would return zero and the count would start at 1.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTO FORMAT mfahmyg Access 1 February 28th, 2008 02:54 PM
DataGridView Auto Format? MLyons10 C# 2005 0 December 5th, 2006 10:26 AM
auto fill field mankoti_mankoti2000 Access 1 May 26th, 2006 08:19 AM
Auto Dating Field anukagni Access 1 March 13th, 2006 09:53 AM
Auto Populate a field ? mar0364 Classic ASP Databases 4 July 9th, 2004 11:10 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.