Solved

Autonumber Format

Posted on 2009-07-07
3
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

730 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