Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Incremental Numbering for clients & Year

Posted on 2013-12-29
6
Medium Priority
?
282 Views
Last Modified: 2013-12-29
I need to create an incremental numbering system based on a client ID and the year. Right now I have a numbering system that works well and increments based on the client that is logged in. It numbers the client records sequentially all starting from 0001. But when the year changes I need that numbering system to start back at 0001. Here's what I currently have that is working fine but now I need to somehow change it to start over when the new year starts

Dim i, a
 i = Me.cboClinicName
Me.txtCRecordID = [txtClinicCode] & Format(Date(),"yy") & Nz(DMax("CRecordID", "tblCogginsDetail", "ClinicName = " & i), 0) + 1

Open in new window


So here's how it looks now for each record

When the clinic name is NEHL or KOS for example:

NEHL130001
NEHL130002
KOS130001
KOS130002
KOS130003

So now what I need to do is restart the last 4 digits of the above sequence  when the year changes. For example:

NEHL130001
NEHL130002
NEHL140001

etc...

How can I rewrite my code to restart this when the year changes?
0
Comment
Question by:Lawrence Salvucci
[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
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 39744927
Try this code:
Dim a As String, b As String
a = Me.[txtClinicCode] & Format(Date, "yy")
b = Nz(DMax("CRecordID", "tblCogginsDetail", "instr(1,CRecordID," & Chr(34) & a & Chr(34) & ") = 1"))
If b = "" Then
    b = a & "0001"
Else
    b = a & Format((Mid(b, Len(a) + 1) + 1), "0000")
End If
Me.txtCRecordID = b

Open in new window

0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39744935
It's not incrementing the last 4 digits of the sequence. It's just putting the same values in the field "NEHL130001".
0
 
LVL 40

Expert Comment

by:als315
ID: 39744952
Can you upload sample DB with this table only and form?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39744958
That's gonna take a little time. Give me a few and I'll upload a copy of it.
0
 
LVL 40

Expert Comment

by:als315
ID: 39744961
Look at my sample
DBincrement.accdb
0
 
LVL 1

Author Closing Comment

by:Lawrence Salvucci
ID: 39744970
Got it working. I had the wrong field name in your code. Thank you for your help. I appreciate it!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

722 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