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

Appending auto increment numbers on a given root

Hello Newsgroup,

at the moment I am coding an archive database for a bank. Every folder
has an own number, following the sheme
x-x-xxx-yyyy
whereas x-x-xxx describes the archive, the storage location and the
shelf, yyyy should be a consecutive number.
If I am using an normal consecutive number, this would mean that it is
- independant from the x-x-xxxx-root - consecutive. I'd prefer to have
for every x-x-xxx- a new-starting consecution, meaning that for every
x-x-xxx, yyyy takes the values from 0000-9999,

is there a way to do so?

greetings
Thorben Grosser

Jul 23 '07 #1
6 2125
Hi,
If I am using an normal consecutive number, this would mean that it is
- independant from the x-x-xxxx-root - consecutive. I'd prefer to have
for every x-x-xxx- a new-starting consecution, meaning that for every
x-x-xxx, yyyy takes the values from 0000-9999,
is there a way to do so?
You can try the following :

Create a table - I've named it "tblRoots" - and insert 2 fields

Field: "Root" as text and primary key
Field: "CurNumber" as long integer

Copy the code below in a standard modul.
In the direct window you can test it:
?GetRootNumber("MyTest")

Regards
Jens

Public Function GetRootNumber(MyRoot As String) As Long

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lgNumber As Long
Dim strCondition As String

Set db = CurrentDb
Set rs = db.OpenRecordset("tblRoots", dbOpenDynaset)

strCondition = "Root = '" & MyRoot & "'"
rs.FindFirst strCondition
If rs.NoMatch Then
lgNumber = 1
rs.AddNew
rs!Root = MyRoot
rs!CurNumber = 1
rs.Update
Else
lgNumber = rs!CurNumber
lgNumber = lgNumber + 1
rs.Edit
rs!CurNumber = lgNumber
rs.Update
End If

GetRootNumber = lgNumber

rs.Close: Set rs = Nothing
db.Close: Set db = Nothing

End Function
Jul 23 '07 #2
Hey Jens,

thanks for your information. I tried to introduce the module into my
Access-File. Still, it reports the detection of an ambigious name
which makes no sense to me as there seems to be no double used name.
Is there any way to receive a more accurate error description or do I
have to look for the needle?

thanks
Thorben Grosser

Jul 23 '07 #3
Hi,
thanks for your information. I tried to introduce the module into my
Access-File. Still, it reports the detection of an ambigious name
which makes no sense to me as there seems to be no double used name.
Is there any way to receive a more accurate error description or do I
have to look for the needle?
Check your References - the refenrence to Microsoft DAO 3.x must be set

Regards
Jens
Jul 23 '07 #4
Well, yes. RTFM :) works great, thanks a lot. Still, there is one
small problem:
No matter if I set the number of decimal places to 4 wether I set the
input scheme to 9999 it only returns values like 1, 2, 3...instead of
0001 0002 0003.
Any ideas?

Thanks
Thorben Grosser

On 23 Jul., 10:33, "Jens Schilling"
<jensschillingBitteLoesc...@fissership.dewrote:
Hi,
thanks for your information. I tried to introduce the module into my
Access-File. Still, it reports the detection of an ambigious name
which makes no sense to me as there seems to be no double used name.
Is there any way to receive a more accurate error description or do I
have to look for the needle?

Check your References - the refenrence to Microsoft DAO 3.x must be set

Regards
Jens

Jul 23 '07 #5
Hi,
No matter if I set the number of decimal places to 4 wether I set the
input scheme to 9999 it only returns values like 1, 2, 3...instead of
0001 0002 0003.
Any ideas?
As the return value of the function is a long integer value - and numbers
know nothing about leading zeros - you could change the return value to a
string.

So change the first line to :

Public Function GetRootNumber(MyRoot As String) As String

And use the format-method to for the return value

GetRootNumber = Format(lgNumber, "0000")

Regards
Jens
Jul 23 '07 #6
On 23 Jul., 14:54, "Jens Schilling"
<jensschillingBitteLoesc...@fissership.dewrote:
Hi,
No matter if I set the number of decimal places to 4 wether I set the
input scheme to 9999 it only returns values like 1, 2, 3...instead of
0001 0002 0003.
Any ideas?

As the return value of the function is a long integer value - and numbers
know nothing about leading zeros - you could change the return value to a
string.

So change the first line to :

Public Function GetRootNumber(MyRoot As String) As String

And use the format-method to for the return value

GetRootNumber = Format(lgNumber, "0000")
thanks a lot, works great

Thorben
Jul 23 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: csomberg | last post by:
SQL 2000 I thought I would throw this out there for some feedback from others. I'd like to know if you feel using MS auto-increment field is a good solution these days or should one grow their...
8
by: Prometheus Research | last post by:
http://newyork.craigslist.org/eng/34043771.html We need a JavaScript component which will auto-submit a form after a set period has elapsed. The component must display a counter that dynamically...
0
by: Santosh | last post by:
Hi, I have a requirement in which I need to create an auto increment column in a file which will be unique. The following is what I am trying to do. 1) I need to use DDS to define the file 2)...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Paulovič Michal | last post by:
hi all, I have problem with SERIAL field type (or sequence functionality). I have table with three columns - ID, IDS, NAME. I want auto-increment IDS grouped by ID. Example: 1, 1, Ferdo 1, 2,...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
0
mmarif4u
by: mmarif4u | last post by:
Hi guys,,, I have simple problem, Problem is that, i want that a php variable create date with numbers, look like this: $rtno = date("md,here some numbers but auto increment start from 001...
11
by: mp- | last post by:
I want to be able to allow people to check their email from my PHP online application. Given only the users 1) email address, 2) username (if applicable) and 3) password - how can I auto detect...
1
by: jimilives | last post by:
I forgot to turn on auto increment when I reinstalled this database and now I have a bunch of NULL values in my ID field for last few hundred inserts, how can I update this table to replace the NULLS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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,...

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.