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, 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 -
Reply With Quote
  #2 (permalink)  
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
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 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



All times are GMT -4. The time now is 11:29 PM.


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