473,387 Members | 1,757 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.

Sequential Number

Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber.
So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

At the moment I'm using a DMax formula on the default value on the
"txtSeqNo" field on the orders form, but my problem is; when two orders are
entered simultaneously they are given exactly the same sequential number.

I have found a vb code on the web that creates a sequential number from a
table and is network friendly, but I don't know how to fix the code to
create the sequential number according to the City.

Set myset = CurrentDb.OpenRecordset("tblSeqNo")
myset.LockEdits = True
myset.Edit
myset!txtSeqNo = myset!SeqNo + 1
SeqID = myset!SeqID
myset.Update
myset.Close

I would appreciate if anyone gives and an idea on how to do this
Nov 12 '05 #1
7 5185
On Thu, 1 Apr 2004 16:40:47 +0000 (UTC), "GAVO."
<ga******@hotmail.com> wrote:
Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber.
So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

At the moment I'm using a DMax formula on the default value on the
"txtSeqNo" field on the orders form, but my problem is; when two orders are
entered simultaneously they are given exactly the same sequential number.

I have found a vb code on the web that creates a sequential number from a
table and is network friendly, but I don't know how to fix the code to
create the sequential number according to the City.

Set myset = CurrentDb.OpenRecordset("tblSeqNo")
myset.LockEdits = True
myset.Edit
myset!txtSeqNo = myset!SeqNo + 1
SeqID = myset!SeqID
myset.Update
myset.Close

I would appreciate if anyone gives and an idea on how to do this


The DMax is fine, it is the timing of it that is the problem. You are
setting it when the record is created. Instead set it at the time the
record is saved. Use the Form's BeforeUpdate event and check for the
NewRecord property.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Me.SeqNo = DMax("SeqNo", "tblOrders") + 1
End If
End Sub

This way the sequenced number happens at the very last instance. The
chance of duplication is very, very small. There is really no need for
the extra table with locking and unlocking.

Also, you would probably want the sequence field indexed without
duplicates.

- Jim
Nov 12 '05 #2
"GAVO." <ga******@hotmail.com> wrote in message
news:c4**********@titan.btinternet.com...
Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber. So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

If an order is deleted do you care that there will be gaps in the sequence?
If you do then you should not store SeqNo in the table and instead consider
generating it in a query when required. Otherwise go with Jim's suggestion.
Nov 12 '05 #3
On Thu, 01 Apr 2004 22:42:27 GMT, "Jim Allensworth"
<ji****@Notdatacentricsolutions.com> wrote:
On Thu, 1 Apr 2004 16:40:47 +0000 (UTC), "GAVO."
<ga******@hotmail.com> wrote:
Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber.
So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

At the moment I'm using a DMax formula on the default value on the
"txtSeqNo" field on the orders form, but my problem is; when two orders are
entered simultaneously they are given exactly the same sequential number.

I have found a vb code on the web that creates a sequential number from a
table and is network friendly, but I don't know how to fix the code to
create the sequential number according to the City.

Set myset = CurrentDb.OpenRecordset("tblSeqNo")
myset.LockEdits = True
myset.Edit
myset!txtSeqNo = myset!SeqNo + 1
SeqID = myset!SeqID
myset.Update
myset.Close

I would appreciate if anyone gives and an idea on how to do this


The DMax is fine, it is the timing of it that is the problem. You are
setting it when the record is created. Instead set it at the time the
record is saved. Use the Form's BeforeUpdate event and check for the
NewRecord property.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Me.SeqNo = DMax("SeqNo", "tblOrders") + 1
End If
End Sub

This way the sequenced number happens at the very last instance. The
chance of duplication is very, very small. There is really no need for
the extra table with locking and unlocking.

Also, you would probably want the sequence field indexed without
duplicates.


I just noticed that you are using City as part of the criteria. So you
might do it like this...

Me.SeqNo = Nz(DMax("SeqNo", "tblOrders", _
"City='" & Me.City & "'"), 0) + 1

Single quotes around the City text value.

- Jim

Nov 12 '05 #4
On Thu, 01 Apr 2004 22:42:27 GMT, "Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote:
On Thu, 1 Apr 2004 16:40:47 +0000 (UTC), "GAVO."
<ga******@hotmail.com> wrote:
Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber.
So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

At the moment I'm using a DMax formula on the default value on the
"txtSeqNo" field on the orders form, but my problem is; when two orders are
entered simultaneously they are given exactly the same sequential number.

I have found a vb code on the web that creates a sequential number from a
table and is network friendly, but I don't know how to fix the code to
create the sequential number according to the City.

Set myset = CurrentDb.OpenRecordset("tblSeqNo")
myset.LockEdits = True
myset.Edit
myset!txtSeqNo = myset!SeqNo + 1
SeqID = myset!SeqID
myset.Update
myset.Close

I would appreciate if anyone gives and an idea on how to do this


The DMax is fine, it is the timing of it that is the problem. You are
setting it when the record is created. Instead set it at the time the
record is saved. Use the Form's BeforeUpdate event and check for the
NewRecord property.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
Me.SeqNo = DMax("SeqNo", "tblOrders") + 1
End If
End Sub

This way the sequenced number happens at the very last instance. The
chance of duplication is very, very small. There is really no need for
the extra table with locking and unlocking.

Also, you would probably want the sequence field indexed without
duplicates.

- Jim


Just a small addition to Jim's answer. If the database is to start life empty (no data) then you need to wrap the DMax in a Nz function otherwise it
will fail when you attampt to add the first record to the table.

In an empty table DMax("SeqNo", "tblOrders") will return Null. Null + 1 = Null.
whereas Nz(DMax("SeqNo", "tblOrders") ,0) will return 0. 0 + 1 = 1

If the underlying table already has data it is a non issue.

Wayne Gillespie
Gosford NSW Australia
Nov 12 '05 #5
It is really important that this sequential number has no duplicates or
gaps, that is one of the reasons why i did not want to use the original
Autonumber, as the user is asked to weather to save or not the record when
closing. I apresiate Jims suggestion about changing the timing of the
formula i already have iin place and does what i want, but im looking for
something that i do not have to worry about, that is why i included that vb
code, which creates a sequential number, but what i dont know is how to use
the "City" field as a criteria.

Thanks.


"John Winterbottom" <as******@hotmail.com> wrote in message
news:c4*************@ID-185006.news.uni-berlin.de...
"GAVO." <ga******@hotmail.com> wrote in message
news:c4**********@titan.btinternet.com...
Hello every one

I have a database with a form called "frmOrders" on that for I need to
create a sequential number for each city apart from the original autonumber.
So the table "tblorders" would look something like this:

OrderID (Autonumber) SeqNo City
1 1 London
2 1 Madrid
3 2 London
4 2 Madrid
5 1 Barcelona
6 3 London
7 4 London

If an order is deleted do you care that there will be gaps in the

sequence? If you do then you should not store SeqNo in the table and instead consider generating it in a query when required. Otherwise go with Jim's suggestion.

Nov 12 '05 #6
"GAVO." <ga******@hotmail.com> wrote in message
news:c4**********@sparta.btinternet.com...
It is really important that this sequential number has no duplicates or
gaps, that is one of the reasons why i did not want to use the original
Autonumber, as the user is asked to weather to save or not the record when
closing.


Regardless of the number generation mechanism, if an order is deleted then
your sequence is going to have gaps. I suggest generating the seq nbr
through code like:
select o1.OrderID, o1.City,
(
select count(*)
from orders as o2
where o2.City = o1.City
and o2.OrderID <= o1.OrderID
) As SeqNo

from orders as o1
Nov 12 '05 #7
On Fri, 2 Apr 2004 15:29:28 +0200, John Winterbottom wrote
(in message <c4*************@ID-185006.news.uni-berlin.de>):
Regardless of the number generation mechanism, if an order is deleted then
your sequence is going to have gaps.


I recently had to implement something similar (SeqNo for Topics,
SeqNo is not primary but of course candidate key).
Since there won't be more than about 20 topics per Recordset in
use I wrapped a SQL-Delete Statement and a renumbering loop in
a transaction.
I should add that the SeqNo is not editable for Users and changed/
created only by functions.
And this db has only max. 3 Users.

Michael

Nov 12 '05 #8

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

Similar topics

6
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a...
5
by: Lapchien | last post by:
I have list of numbers in a table (originally from autonumber in a different database) from 1 to 1,000,000. The list is not in sequential order - there are loads of numbers missing. How can I...
4
by: cliff williams | last post by:
how can I set a form so that when i open it , it appears with the next sequential number. I want to set the number pattern and not use autonumber
7
by: GAVO. | last post by:
Hello every one I have a database with a form called "frmOrders" on that for I need to create a sequential number for each city apart from the original autonumber. So the table "tblorders" would...
2
by: Mike Kingscott | last post by:
Hi all, I'd building an app that posts to a web service. One of the things that is required in the soap header is a sequential number appended to a ref, i.e. "IGI1001", "IGI1002", etc. ...
9
by: Nooby | last post by:
New to Access here. I inherited a db that has the first column as an automatically generated sequential number. I want to bump it up, but for the life of me I can't figure out how to do it. Is...
1
maxamis4
by: maxamis4 | last post by:
Hello folks, I have two forms a parent form and a subform. The parent form is an unbound form while the subform is a form that contains all a list of what I like to call 'in stock ' phone...
5
by: p3rk3le | last post by:
So, I'm about to do a sequential search on a table (n contents) of random numbers. I have to print the average between the number of comparisons and the contents of the table (n) and the...
9
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what 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: 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
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: 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...
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,...
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...

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.