Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2008, 02:00 PM
Registered User
 
Join Date: Feb 2008
Location: kajang, selangor, Malaysia.
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,
- FAHMY -
Reply With Quote
  #2 (permalink)  
Old March 28th, 2008, 07:36 AM
Authorized User
 
Join Date: Mar 2007
Location: Sydney, NSW, Australia.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
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

Cheers
Darren

Reply With Quote
  #3 (permalink)  
Old April 4th, 2008, 07:24 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:23 PM.


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