473,769 Members | 6,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning sequential numbers

Hi

I need to assign sequential invoice numbers to orders starting from the last
highest number + 1. I have tried the following code;

UPDATE Orders SET Orders.[Invoice No] = DMax("[Invoice No]","Orders") +1
WHERE Orders.[Invoice No]) Is Null AND ...

The problem is that all orders get the same number which is the last highest
number + 1. Apparently the query does not recalculate DMax("[Invoice
No]","Orders") +1 for each record and instead only gets the value once in the
beginning and assigns this same value to all the records. How can I make it
work?

Thanks

Regards
Feb 13 '06 #1
2 5119
John

Are you trying to do this "in bulk"? How many do you have to update? It
might be faster to just open the table and start typing unless you have
several hundred or more...

The DMax() + 1 approach works great ... when the record is being saved.
There's no reason it would update (itself) after each row is updated. Look
to add this function as part of how you save a new record (i.e., via a
form).

Regards

Jeff Boyce
<Office/Access MVP>

"John" <Jo**@nospam.in fovis.co.uk> wrote in message
news:ee******** ******@TK2MSFTN GP09.phx.gbl...
Hi

I need to assign sequential invoice numbers to orders starting from the
last highest number + 1. I have tried the following code;

UPDATE Orders SET Orders.[Invoice No] = DMax("[Invoice No]","Orders") +1
WHERE Orders.[Invoice No]) Is Null AND ...

The problem is that all orders get the same number which is the last
highest number + 1. Apparently the query does not recalculate
DMax("[Invoice No]","Orders") +1 for each record and instead only gets the
value once in the beginning and assigns this same value to all the
records. How can I make it work?

Thanks

Regards

Feb 13 '06 #2
Here is a function that can work: Put this in a public module:
Public Function NextNumber(varF ield As Variant, Optional varValue As
Variant) As Long
Static lngNextNumber As Long

If IsMissing(varVa lue) Then
lngNextNumber = lngNextNumber + 1
Else
lngNextNumber = varValue
End If
NextNumber = lngNextNumber
End Function
Then "prime" the function with a starting value by executing this from
the Immediate window:

call NextNumber("Som eValue",0)

Finally, add a column to your query like this:
RowNumber: NextNumber([SomeFieldInQuer y])

(field name is REQUIRED, but not significant -- any one will work)


On Mon, 13 Feb 2006 22:40:40 -0000, "John" <Jo**@nospam.in fovis.co.uk>
wrote:
Hi

I need to assign sequential invoice numbers to orders starting from the last
highest number + 1. I have tried the following code;

UPDATE Orders SET Orders.[Invoice No] = DMax("[Invoice No]","Orders") +1
WHERE Orders.[Invoice No]) Is Null AND ...

The problem is that all orders get the same number which is the last highest
number + 1. Apparently the query does not recalculate DMax("[Invoice
No]","Orders") +1 for each record and instead only gets the value once in the
beginning and assigns this same value to all the records. How can I make it
work?

Thanks

Regards


*************** *******
ja************* *@telusTELUS.ne t
remove uppercase letters for true email
http://www.geocities.com/jacksonmacd/ for info on MS Access security
Feb 14 '06 #3

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

Similar topics

6
8084
by: cjm | last post by:
I need to group records and assign a setid to the group. I have a table with data that looks like this ColA ColB 94015 01065 94016 01065 94015 01085 94015 01086 33383 00912 32601 00912
6
12711
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 block of "x" number of sequential part numbers - say for example 5. If my database had the following numbers available: 101 104 105 110
5
3209
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 identify what numbers are missing? Thanks, Lap (I'd like to then use this 'missing number list' to use for new records, instead of autonumber - I think I need to use DMax - can someone summarise
14
12048
by: amywolfie | last post by:
Hi All: I know this is simple, but I just can't seem to get there: I need to sort a table by a text field (txtDescription), then assign sequential numbers to the field SEQUENCE in table. Every time a new record is added, the all SEQUENCE #'s must be reset. The re-numbering will be triggered by an EXPORT button.
3
1514
by: John | last post by:
Hi I have a jobs table in which a client can be assigned to multiple jobs. Now I need to assign invoice numbers to jobs such that all jobs belonging to one client get the same first number, all jobs belonging to second client get the second invoice number and so on. Basically I need to batch jobs by client so they all appear on the same invoice rather than individual invoice for each job. How can I achieve this? Thanks
1
2455
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 numbers. with in that subform the user has the ability to select between to radio buttons to do a bulk selection. The first option lets the user select the first X amount of numbers that he or she wants. The second option selects X amount of numbers but...
6
6969
by: jtidwell | last post by:
I am developing a Work Order Database for my job. I have a combo box with "Contract Numbers" to select from. When you select on any Contract Number I need a new "Work Order Number" to appear. There are 10 different contract numbers so I need 10 different work order numbers (N10001, O100001, etc..) to generate sequential for each new record.
7
2897
by: Constantine AI | last post by:
Hi i have a table called preordlin where a csv file imports there data into it. I have an attribute called 'ItemNo' which i need to input sequential numbers for like an AutoNumber but one that resets itself everytime a csv file has been inputted. The code i have so far is simple but incorrect: Set db = CurrentDb() Set rst = db.OpenRecordset("SELECT * FROM preordlin") Do rst.Edit rst!StkID = DLookup("",...
9
2948
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 seek, but, as is rather typical, I could understand neither the question nor the answer. I am hopeful that someone in this forum can provide me with suitable guidance. THE ISSUE I am working in Access 2003. The database I am preparing...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10048
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3963
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 we have to send another system
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.