Wrox Programmer Forums
| 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 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, 01:58 PM
Registered User
 
Join Date: Feb 2008
Location: kajang, selangor, Malaysia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default AUTO FORMAT

Hi Friends...

I have a problem... I create a field named member_ID 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 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 -
 
Old February 28th, 2008, 02:54 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

If I needed a string like this as an ID field, I would create it on the Before Insert event of the data entry form. This will create the string as the record is inserted, which means it is generally not available for viewing until after the record is created.

I would use an AutoNumber field, that is hidden, since this will allow Access to manage the final digits in the string, and prevent conflicts that could be difficult coding. The issue here is that Access will only create the AutoNumber after the first field has been filled in, so the Before Insert is your best bet.

If your AAAA is always the same, then on the Before Insert event of the form you might put:

Dim sString As String

sString = "AAAA-"
sString = sString & Right(DatePart("yyyy", Date()), 2)
sString = sString & "-" & Me.AutoNumberField

This will derive your number. The last issue is the number of 0 before the integer that is in the AutoNumber field ("10" instead of "00000010"). I have to go to a meeting so can't solve that now. Anyone else?

Did that help?



mmcdonal

Look it up at: http://wrox.books24x7.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTO FORMAT field mfahmyg Access 2 April 4th, 2008 07:24 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
Convert Rich Text Format to Ordinary Format in ASP Andraw Classic ASP Basics 1 August 31st, 2007 10:05 AM
DataGridView Auto Format? MLyons10 C# 2005 0 December 5th, 2006 10:26 AM
Auto Refresh and Auto Delete deontae45 VB.NET 2002/2003 Basics 1 September 29th, 2006 04:53 PM





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