473,399 Members | 4,192 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,399 software developers and data experts.

Custom Primary Key

I'm trying to work out how to format a custom primary key using the current year as part of the key. I've copied code which I use 'OnCurrent' for the form. The code I've copied is:

Private Sub Form_Current()
If Me.NewRecord Then
Me!RDNo = Format(Nz(DMax("val([RDNo])", "TblDocumentRequests"), 0) + 1, "000000")
End If

End Sub
What this should do (based on what it does in my other table) is automatically update the primary key plus one of whatever the last number used was. However, I want is the primary key to read as "RD08-001" (with the 08 being the current year and the 001 to be the bit updated automatically).I've tried every which way to update the code to do this but I just can't get it to work. Please help!!
Dec 9 '08 #1
5 2881
ADezii
8,834 Expert 8TB
@PotatoChip
This will definitely work as long as you maintain the strict Format that you demonstrated, but there is probably a better solution that another Member will come up with so be patient. Be advised that that does not take into consideration a Year transition like from 08 to 09. The first Record for the New Year would have to be manually entered, or the logic would have to be extended.
Expand|Select|Wrap|Line Numbers
  1. Me![PDNo] = Left$(DLast("[RDNo]", "tblDocumentRequests"), 2) & Format$(Now(), "yy") & _
  2.        "-" & Format$(Val(Right$(DLast("[RDNo]", "tblDocumentRequests"), 3)) + 1, "000")
Dec 10 '08 #2
I tried what you suggested and it didn't work. I kept getting error messages and had to delete parts of the code.
Dec 10 '08 #3
ADezii
8,834 Expert 8TB
@PotatoChip
Download the Attachment and have a look-see
Dec 11 '08 #4
I don't know what I was doing wrong but I copied and pasted your code into my form and it works perfectly!

Thanks so much!!!
Dec 12 '08 #5
ADezii
8,834 Expert 8TB
@PotatoChip
You are quite welcome.
Dec 12 '08 #6

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

Similar topics

8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
0
by: Khuzema | last post by:
Dear All, I am using issue tracker architecture and developed business object for my application. Now, in VS Beta 2, I humbly want to know how i can have same feature as dataset, in my business...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
2
by: Brandon | last post by:
I created a setup project in VS.NET 2k5 and added an additional dialog to ask the user where they would like to place icons for my application. The options are Desktop and QuickLaunch Menu. When...
2
by: J R M | last post by:
I've developed a custom control (it's basically a drop-down list and then a couple of textboxes to include meta-data for the selection) that I'm embedding into another custom control (the idea is...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
6
by: Jonathan Wood | last post by:
Although this will be a challenge at my level of ASP.NET knowledge, I'm thinking I should implement my own membership provider class. Looking over the methods I must implement, a number of...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.