473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do I customize a job number?

I am trying to autopopulate a field (JobNumber) in a table (JobDatabase). This field is a primary key for the table and I want to force it to be numbered per our job numbering system. Also I would like it to automatically assign sequentially when new records are created.

Our job numbering system is a hybrid which is in the following format "MMYY###".

For example:
New record is created in January 2011 and is the 4th one created for the month. The job # would be 0111004.

The next record created in January of 2011 would be numbered 0111005.

The first record for the following month (February 2011) would be 0211001.

How would I do this in MS Access/VBA?
Dec 1 '10 #1
1 1279
colintis
255 100+
Hi Anthony,

The below part of code should work for you
Expand|Select|Wrap|Line Numbers
  1. Dim strDate As String
  2. Dim RecCnt As Integer
  3. Dim RecNbr As String
  4. Dim strRec As String
  5.  
  6. 'Get current month & year
  7. strDate = Month(Date) & Year(Date)
  8.  
  9. 'Check if there's any other current month records
  10. RecCnt = DCount("<Your Record ID>" _
  11.                 , "<Your Table>" _
  12.                 , "<Your Record ID> LIKE '" & strDate & "*'")
  13.  
  14. If RecCnt > 0 Then
  15.     'Get the highest record# of the month
  16.     RecNbr = DMax("<Your Record ID>" _
  17.                   , "<Your Table>" _
  18.                   , "<Your Record ID> LIKE '" & strDate & "*'")
  19. Else
  20.     'First record of the month
  21.     RecNbr = strDate & "000"
  22. End If
  23.  
  24. 'Now we have the new record number
  25. strRec = CInt(RecNbr) + 1
I would recommend to have that record number in the format of YYMM### instead of MMYY## for better searching purpose.
Dec 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

79
by: Klaus Bonadt | last post by:
In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
14
by: deko | last post by:
The below code dials a phone number when the subform datasheet cell containing the number is double clicked. The problem is that the dialer application (c:\windows\dialer.exe) pops up windows on...
1
by: Gianmaria | last post by:
Hi, i'm workin on a deployment project... i added two custom screen to make some tasks. 1) I need that user insert a serial number for my setup.. next i check the validity of this serial by a...
0
by: Maria | last post by:
Hi I am new to .NET and would like to know how do we customize the apprearance of a datagrid Precisely, I would like to make ONE row appear in BOLD, and I would like to specify the number of...
1
by: Amy Snyder | last post by:
I have a datagrid where I incorporate paging and sorting. My datagrid page mode is set to numeric. Is there a way for me to customize this to display something like this in the page header: ...
4
by: Fred | last post by:
Hello, datagrids have GridLines, BorderWidth, BorderColor, ItemStyle.CssClass, ShowFooter ... properties, which can be used to customize the way they look when printed, how does one achieve the...
1
by: JT | last post by:
Hi, We have 2 servers having the same web site running on port 8080. These two servers are load balanced and have DNS name, e.g. my.server.com. Now on both of these two servers, we put the same...
0
by: gkinu | last post by:
I have a Visual Studio 2005 Windows Application. I want to customize the setup. Specifically, I want the following. 1. If not already done, the database to be created and configured as necessary 2....
0
by: Sky | last post by:
I have an Access 2003 front-end database with custom toolbars. The toolbars work fine. One annoying feature is that at the far right edge of each custom toolbar there a small dropdown arrow....
2
by: Coni | last post by:
How do I customize an ID as primary key to be anything other than numbers. For example what if I wanted to create an ID based on the last three letters of a last name and the extension number. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.