Solved

Autonumber Format

Posted on 2009-07-07
3
381 Views
Last Modified: 2013-11-28
Hi Experts,

I'm having a table that has a primary field as auto number. I want to add year to this field and have it reset after each year. Can anybody help me with this please?
 
Currently it's format as 0"8-"000 but I want it to be using a datetime field called DateofService and use the year mentioned there and create/append the autonumber

For example: DateOfService: 05/01/2007 then GC # 07-001 and if there are other records for that year it should increment it sequentially. If the year changes it should reset and start with the same (05/01/2008 08-001).

Thanks

Table name: TBL_BCInformation

Fields: GC # (primary key) autonumber

           DateofService Datetime

Open in new window

0
Comment
Question by:Samoin
  • 2
3 Comments
 
LVL 84
ID: 24799671
You cannot format an Autonumber field. You can create sequential numbers for each year, but you cannot do this at the table level. You must do it through your forms.

Do you have multiple users in this database? If you do, the task is much more involved.
0
 
LVL 1

Author Comment

by:Samoin
ID: 24803642
Hi LSMConsulting,

Can you show how I can create a custom sequential number that can be used as primary key? Yes I do have multiple users in this database.

Thanks
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 24804203
That's a broad topic - multiple users with a customized number. You can't just use DMax, since it's entirely possible that two users will be building a new record at the same time. Here's some light reading on the subject:

http://support.microsoft.com/kb/210194
http://support.microsoft.com/kb/191253
http://www.tek-tips.com/faqs.cfm?fid=4634

In regards to your format, you'd be better off building that as needed. You're already storing the date your record is created; if you also store a "sequence" number that is relative to your Year, you can then build your "ID" key as needed. For example, if I have a column in my table named "lSequence", and my date field is named "dServiceDate", on my form I can do this:

Me.YourIDField = "GC # " & CStr(Year(dServiceDate)) & "-" & CStr(Me.lSequence)

Your lSequence field would be, basically, your "counter" in the link examples above. Each time a user needed to add a record, you'd have to grab the next value and use it.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now