473,480 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Autonumber Using alphanumeric (text and number) data type

mose Mbugua
17 New Member
How can i generate the next available record number to appear in the primary key field on a data entry form?

For example, i want to add (admit) a new student but the primary key "Admission Number" has both text and numbers (C001).

When i open the Admission form i wish it to look at the last admission number record, add 1 to it, then prepopulate the id field
Nov 20 '14 #1
3 3709
jforbes
1,107 Recognized Expert Top Contributor
This can get a little tricky, timing wise, if multiple people are creating records. So if you are running where multiple people are pulling a Key, you will want to pull the key and save the record right away, or wait to create the key on save.

Either way it's basically the same. Some people like to use a Key Table but most of the time it's easiest to just look up the next value with a function. Here is one:
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
  6.  
You can use this type of function as the DefaultValue for a Control on a Form or have it called from VBA if you are doing some magic to make sure all your many users are getting unique values.
Nov 20 '14 #2
mose Mbugua
17 New Member
i would like it to be called from vba but i don't know how to do it. am a newbie to code. which field on the control's property sheet should i type the code?
Mar 16 '15 #3
jforbes
1,107 Recognized Expert Top Contributor
The easiest way is to put the formula in the DefaultValue Property for your AdmissionNumber.
Mar 16 '15 #4

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

Similar topics

3
4530
by: J. C. O'Connell | last post by:
hi, I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN. HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD? I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I DONT...
10
8590
by: Ramprasad A Padmanabhan | last post by:
Hello all, On my linux box ( redhat 7.2 ), I have been using char as a boolean data type. In order to save on the number of bytes as compared to using int or short int. typedef char boolean;...
5
1866
by: dananrg | last post by:
I was messing around with the native ODBC module (I am using Python in a Win32 environment), e.g: import dbi, odbc ....and it seems to meet my needs. I'd rather use a module that comes...
3
3260
by: Mejmeyster | last post by:
Hi Everyone, I have a table in which one of the text fields has become too small (since it only holds 255 characters). To remedy that, I'm trying to change the data type of that field to "memo"...
4
5768
by: kcddoorman | last post by:
I'm trying to make a multi criteria server filter and everything works fine when filtering for strings. When I add a number field to the filterable set I run into problems. Here is the VBScript I'm...
5
7076
by: Amit Parmar | last post by:
Hi Everybody, I am fetching number data from a table. i want to add '$' sign to this data. I already tried "TO_CHAR" function. This works fine but it converts number data type to string data...
1
1609
by: foxygrandma | last post by:
I am having data type problems. The first thing I had to do was convert the weight of one column from kg to lb. I did this by multiplying by 2.20462262 and updating a new column, however, the...
2
9482
by: JoeKid09 | last post by:
Hi Guys, I'm working on converting a large table with a field that has numeric values in text data type. When I do the conversion in Access automatically some records don't get converted. The...
3
1612
by: jleonheart | last post by:
Hi All, I have a table that use an Auto Number (Data type) as my primary key. I want my field to be look like this. WJ-2012-00001 ---> first entry. "WJ" , "-" and "2012" --->...
0
6912
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
7052
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
7092
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...
1
6744
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...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.