p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   AUTO FORMAT field (http://p2p.wrox.com/showthread.php?t=66275)

mfahmyg February 28th, 2008 02:00 PM

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,

darrenb March 28th, 2008 07:36 AM

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


SerranoG April 4th, 2008 07:24 AM

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

All times are GMT -4. The time now is 06:34 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.