Solved

Autonumber Format

Posted on 2009-07-07
3
386 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 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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

687 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