Dear Friends,
I have a primary Key called the Solar Lantern No in a table called Beneficiary. The number has a format, namely, 4WS0-01; 02; 03 etc. the solar lantern no starts with 4WS0. how do we do this in Access . the Solar Lantern No increases on its own.... - the field in the recordset Beneficiary are:
-
-
solar lantern no, PK
-
Name, Text
-
Motivator, Text
-
cost, Numeric
looking forward to hear from you.
Thanks
Sajit
6 1236
Your question was vague but I assume you want to increment the last part of your string by 1 each time based on a trigger.
Here is the code. -
Dim vLng As Long
-
Dim vValString As String
-
Dim vText As String
-
Dim vLen As Long
-
-
' get the length of the string
-
vLen = Len(Trim(Me.Text10))
-
' extract the last set of numbers
-
vText = Mid(Trim(Me.Text10), 6, vLen - 5)
-
'convert the number string to numeric
-
vLng = Val(vText)
-
' increment the value by 1
-
vLng = vLng + 1
-
' convert the number back to a string
-
vValString = CStr(vLng)
-
' conecate the original string prefix and the new numeric string
-
vValString = Mid(Trim(Me.Text10), 1, 5) & "0" & vValString
-
' do what you want with the new string
-
Me.Text12 = vValString
-
cheers,
Dear Friends,
I have a primary Key called the Solar Lantern No in a table called Beneficiary. The number has a format, namely, 4WS0-01; 02; 03 etc. the solar lantern no starts with 4WS0. how do we do this in Access . the Solar Lantern No increases on its own.... - the field in the recordset Beneficiary are:
-
-
solar lantern no, PK
-
Name, Text
-
Motivator, Text
-
cost, Numeric
looking forward to hear from you.
Thanks
Sajit
Dear Friends,
I have a primary Key called the Solar Lantern No in a table called Beneficiary. The number has a format, namely, 4WS0-01; 02; 03 etc. the solar lantern no starts with 4WS0. how do we do this in Access . the Solar Lantern No increases on its own.... - the field in the recordset Beneficiary are:
-
-
solar lantern no, PK
-
Name, Text
-
Motivator, Text
-
cost, Numeric
looking forward to hear from you.
Thanks
Sajit
The following code will produce the next [Solar Lantern No] in sequence: -
"4WSO-" & Format$(Val(Right$(DLast("[Solar Lantern No]", "Beneficiary"), 2)) + 1, "00")
Dear Friends,
I have a primary Key called the Solar Lantern No in a table called Beneficiary. The number has a format, namely, 4WS0-01; 02; 03 etc. the solar lantern no starts with 4WS0. how do we do this in Access . the Solar Lantern No increases on its own.... - the field in the recordset Beneficiary are:
-
-
solar lantern no, PK
-
Name, Text
-
Motivator, Text
-
cost, Numeric
looking forward to hear from you.
Thanks
Sajit
The following code will produce the next [Solar Lantern No] in sequence, in the format 4WSO-00:- Retrieve the Last [Solar Lantern No].
- Extract the last 2 values.
- Increment it by 1.
- Reformat the Number "00".
- Append it to the Base String.
- NOTE: Logic only valid up to 4WSO-99.
-
"4WSO-" & Format$(Val(Right$(DLast("[Solar Lantern No]", "Beneficiary"), 2)) + 1, "00")
Both code will work. The only difference is my has no limit and I kept the leading 0 for you (easy to remove if you want). I broke it out so the logic should be easy to understand. Adezi has spelled out the logic nicely.
cheers, The following code will produce the next [Solar Lantern No] in sequence, in the format 4WSO-00:- Retrieve the Last [Solar Lantern No].
- Extract the last 2 values.
- Increment it by 1.
- Reformat the Number "00".
- Append it to the Base String.
- NOTE: Logic only valid up to 4WSO-99.
-
"4WSO-" & Format$(Val(Right$(DLast("[Solar Lantern No]", "Beneficiary"), 2)) + 1, "00")
Both code will work. The only difference is my has no limit and I kept the leading 0 for you (easy to remove if you want). I broke it out so the logic should be easy to understand. Adezi has spelled out the logic nicely.
cheers,
The only difference is my has no limit and I kept the leading 0 for you (easy to remove if you want).
If I am not mistaking you, you simply cannot remove the leading 0 and expect to generate the next number in sequence. If there is no limit to the numbering system then perhaps it needs to be reformatted to:4WSO-000000 which would allow values from 4WSO-000001 to 4WSO-999999 inclusive.
I kept it the way he orginally had it so the results would be
4WSO-01
4WSO-02
.
.
4WSO-010
4WSO-011
.
etc.
I don't see a problem except the limitation of the field length he has set.
If he wants to drop the 0 after it reaches 10 then he just need to put an IF statement that looks to see if the new number is greater than 9 then drop the leading 0.
cheers,
If I am not mistaking you, you simply cannot remove the leading 0 and expect to generate the next number in sequence. If there is no limit to the numbering system then perhaps it needs to be reformatted to:4WSO-000000 which would allow values from 4WSO-000001 to 4WSO-999999 inclusive.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Simmons |
last post by:
How is it that even though I have the column "username" in my database set
as a Primary key, using my PHP script to add new users to the database works
without any errors even when signing up using...
|
by: Ghulam Farid |
last post by:
Hi
i have a table with primary key defined on col1 and col2. now i want to
have col3 also included in primary key. when i alter the table it gives
me error for duplicate rows. there is an option...
|
by: Mavis Tilden |
last post by:
Hi all,
So I've been reading the newsgroups, and reading a few books trying to learn
SQL and SQL Server 2000. The books tell me I need a Primary Key, and that
every table should have one. I know...
|
by: 101 |
last post by:
Taking a course on SQL. They are saying you can get better performance by
having multiple files for a group.
They then graphically show an example of "Primary" with multiple data files.
I have...
|
by: serge |
last post by:
I ran into a table that is used a lot. Well less than
100,000 records. Maybe not a lot of records but i believe
this table is used often. The table has 26 fields, 9 indexes
but no Primary Key at...
|
by: shenanwei |
last post by:
I have a primary server and backup server located in different physical
sites.
The primary server is live and ship logs to backup site every 5
minutes.
The primary server is being full online...
|
by: misscrf |
last post by:
Ok I have 2 issues.
1) I have a main candidate form with 2 subforms on a tab control:
http://www.geocities.com/misscrf/images/contactcontinouscheckbox.jpg
I have been encouraged to add these...
|
by: Thomas A. Anderson |
last post by:
I am a bit confused in creating a composite primary key. I have three table
with two of the tables containing primary keys. I have two of the tables
(each with a primary key) having one to many...
|
by: Challenge |
last post by:
Hi,
I got error, SQL1768N Unable to start HADR. Reason code = "7", when I
tried to start hadr primary database. Here are the hadr configuration
of my primary db:
HADR database role ...
|
by: Peter |
last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys
and Unique.
The following SQL statement creates a Bands tables for a database of
bookings Bands into Venues, where the...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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...
|
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: 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...
| |