?
Solved

Autonumber Format

Posted on 2009-07-07
3
Medium Priority
?
388 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 85
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

752 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