473,385 Members | 1,343 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,385 software developers and data experts.

Custom Primary Key

I am trying to create a custom Primary Key (PK) in access. What I am trying to do is create a key where the first part (prefix) of the key is static and will be 'ABC', 'DEF', and 'GHI' for instance. The second part of the key is numeric and sort of auto-generated. I can't use the auto-numbering feature in Access because the number should be sequential with whatever prefix it has. So I should be able to have ABC001, ABC002, DEF001, and DEF002. Not sure how to go about doing this. I know you can create a PK with two different fields but how could I go about automating the number portion of the PK, and how can I concatenate the result to display in a form?

Any help would be appreciated!
May 4 '15 #1
2 1946
jforbes
1,107 Expert 1GB
This post might get you going in the right direction: http://bytes.com/topic/access/answer...mber-data-type

I copied the Code over to make it easier to read this post:
Expand|Select|Wrap|Line Numbers
  1. Public Function getKey(ByRef sTable As String, ByRef sField As String, ByRef iKeyLen As Integer, ByRef sPrefix As String) As String
  2.      Dim sLastKey As String
  3.      sLastKey = DMax(sField, sTable)
  4.      getKey = sPrefix & Right("00000" & Val((Right(sLastKey, Len(sLastKey) - Len(sPrefix))) + 1), iKeyLen - Len(sPrefix))
  5.  End Function
I think whether or not it will work right out of the box for you depends on how you want to determine the prefix.
May 4 '15 #2
zmbd
5,501 Expert Mod 4TB
also use the site search using (w/o quotes :) )
" ms access serial number "
or "ms access sequence number"
You will turn up a few threads that cover this topic... some in great detail :)

Once you get your code/sql together, if you are still having issues, please don't hesitate to post back :)
May 4 '15 #3

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...
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...
3
by: AMD_GAMER | last post by:
I currently have a website which is using ASP.NET 2.0, C#, and SQL Server 2005. The website will be used to enter grants for a university. When a new grant is entered, I need to generate a primary...
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...
5
by: PotatoChip | last post by:
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...
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...
3
by: Mohammed Abdul | last post by:
Dear All, I know that this question was asked many times but I am new to access and programming field. I have created a tracking DB where incidents/accidents are tracked by Event ID number for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.