473,783 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assigning Sequence Numbers to Multiple Rows of Data Problem

129 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.     Set db = CurrentDb()
  2.     Set rst = db.OpenRecordset("SELECT * FROM preordlin")
  3.  
  4.     Do
  5.         rst.Edit
  6.         rst!StkID = DLookup("[StkID]", "stkmas", "[StkShortDesc] ='" & rst!StkShortDesc & "'")
  7.         rst!Price = DLookup("[SalePrice1]", "primas", "[StkID] =" & rst!StkID)
  8.         rst!Cost = DLookup("[CostPrice1]", "primas", "[StkID] =" & rst!StkID)
  9.         rst!ItemNo = [ItemNo] + 1
  10.         rst.update
  11.         rst.MoveNext
  12.     Loop Until rst.EOF
  13.     rst.Close
  14.     Me.Requery
  15.     Set rst = Nothing
The rst!ItemNo = [ItemNo] + 1 works and inputs the numbers 1 and 2 correctly in the rows of data, however when it comes to the 3rd and 4th row of data it still states that it is ItemNo 2. I know the reason for this which is because the code is looking at row 1 each time and then + 1 to the result.

I know i could use an autonumber but i require a sequence number filler code instead as the number have to reset themselves each time an order is being placed.

Is there a way i can tell the code to look at the previous row (ItemNo) and then + 1 to it? I have tried but unfortunately i have failed each time.

Any help would be much appreciated!
Sep 4 '08 #1
7 2897
NeoPa
32,577 Recognized Expert Moderator MVP
It seems to me that this question (although not quite a duplicate possibly) has been answered adequately in Generating Automatic PO Numbers via SQL within Loop Procedures.
Sep 5 '08 #2
Constantine AI
129 New Member
Not anymore sorry i am just about to add to this question, which is relevant and different from the one you answered for me, thanks by the way.
Sep 5 '08 #3
Constantine AI
129 New Member
I have a table called 'preordlin' and one called 'ordlin', each contains the same fields. The preordlin table is used for csv importing, sorting and cleaning the data before it gets imported into the ordlin table. When an item of stock appears in the preordlin table it creates an 'ItemNo' (Sequence coding). So the more stock items the more ItemNos get assigned to these stock items.

I have structured the code below to look at an existing order number and find the last inputted 'ItemNo' so i can carryon from the last entry if a late stock item needs inputting onto an order. At present the numbers starts from scratch which is no good to me. So i created the code below;

Expand|Select|Wrap|Line Numbers
  1.     Dim db As Database
  2.     Dim rst As Recordset
  3.     Dim rst2 As Recordset
  4.     Dim SeqItemNo As Integer
  5.  
  6.     DoCmd.SetWarnings False
  7.  
  8.     Set db = CurrentDb()
  9.     Set rst2 = db.OpenRecordset("SELECT * FROM ordlin WHERE (((ordlin.OrderNo)=[Forms]![frmPreSOLineAdd]![OrderNo]) AND ((ordlin.ItemNo)>0)) ORDER BY ordlin.ItemNo")
  10.  
  11.         rst2.MoveLast
  12.         SeqItemNo = rst2!ItemNo
  13.         rst.Close
  14.  
  15.     Set rst = db.OpenRecordset("SELECT * FROM preordlin")
  16.  
  17.     Do
  18.         rst.Edit
  19.         rst!StkID = DLookup("[StkID]", "stkmas", "[StkShortDesc] ='" & rst!StkShortDesc & "'")
  20.         rst!Price = DLookup("[SalePrice1]", "primas", "[StkID] =" & rst!StkID)
  21.         rst!Cost = DLookup("[CostPrice1]", "primas", "[StkID] =" & rst!StkID)
  22.         rst!ItemNo = rst!ItemNo + SeqItemNo
  23.         rst.update
  24.         SeqItemNo = SeqItemNo + 1
  25.         rst.MoveNext
  26.     Loop Until rst.EOF
  27.     rst.Close
  28.     Me.Requery
  29.     Set rst = Nothing
  30.  
  31.     DoCmd.SetWarnings True
I am certain this code would work providing i didn't receive an error which says Too Few Parameters: Expected 1. I have checked with the help option and checked that what i have done is correct but i can't see where i am going wrong!

Could anyone please suggest something? The code errors on line 9
Sep 5 '08 #4
NeoPa
32,577 Recognized Expert Moderator MVP
Pleased to help.

Adding is fine, but consider the delay. It may be that posting a new one might give it more attention than adding to this. Only you know the details so do as you think is most appropriate.
Sep 5 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. In line 9 you have a reference in the SQL to the control OrderNo on your form. Although such queries do work from the Query Editor, in opening a recordset from code the JET database engine will not recognise this as a valid field name, and will give you the rather confusing parameter error message as a result.

You need to supply the value of the control within the SQL statement, not the full reference to the name of the control, as follows. Use the first version if OrderNo is a string, the second if it is a number:
Expand|Select|Wrap|Line Numbers
  1. WHERE (((ordlin.OrderNo)= '" & [Forms]![frmPreSOLineAdd]![OrderNo] & "') AND ...
  2. WHERE (((ordlin.OrderNo)= " & [Forms]![frmPreSOLineAdd]![OrderNo] & ") AND ...
-Stewart
Sep 5 '08 #6
Constantine AI
129 New Member
Thanks for that, it worked a treat. Cheers
Sep 5 '08 #7
NeoPa
32,577 Recognized Expert Moderator MVP
Well spotted Stewart.

I didn't even know that was a restriction in DAO recordsets. I would never recommend using that in a SQL string created in VBA anyway, so I suppose I've just never come across the problem.

I would certainly recommend doing it the way you suggest :)
Sep 5 '08 #8

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

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
8724
by: python1 | last post by:
I apologize if this is redundant. How would one fill an empty column with a sequence of numbers? The column exists in a table with aproximately 1000000 rows of data. I believe in oracle the following would work: update foo set bar = rownum; ....but 'rownum' does not seem to exist in mssql. The numbers do not need to be in order, but I would like to keep them somewhat small.
6
1413
by: James Liu | last post by:
I did some search and didn't find anything about whether Yokon will support sequence object. Appreciate it if you can reply with some resources. Thanks, James
4
7733
by: Kamran K | last post by:
Hello I have created a client server application using C#. Existing application is using random number on client side to generate sequence numbers that are then assigned to transactions. This results in duplicate sequence numbers across multiple users. Solution to this problem is to generate the sequence number on the server. Since this is not an ASP app, I cannot use Global.asax Application object to keep track of begin application.
4
538
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from the sequence and write to the field. Sometimes, however, these sequence numbers will be discarded (after a transaction is complete), and thus available for use. During the transaction, however, any drawn numbers need to be unavailable. I would...
5
1992
by: jacob.dba | last post by:
I have a table with first name, last name, SSN(social security number) and other columns. I want to assign group number according to this business logic. 1. Records with equal SSN and (similar first name or last name) belong to the same group. John Smith 1234 Smith John 1234 S John 1234 J Smith 1234 John Smith and Smith John falls in the same group Number as long as
12
5231
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's RAND(). any ideas? I suppose I could use the current rancom number as the seed for the next random number. but would that really work?
17
3264
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
482
28027
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
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
8968
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...
0
6737
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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
4044
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.