473,794 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sequential numbering in a query

I have a table which has employee number. I have attempted to creat a
function whic will derive a unique number for each record how ever the
code below only returns 10,000 for all records. What I am doing wrong? I
am I right in saying that In assuming that I dont to loop since I am
returnign this for a every record in query.
Your help will be greatly appreciated.

Function Generate_Number (emp_no As Variant) As Variant
Dim strSQL As Variant
Dim rst As Recordset
Dim Counter As Variant
counter = 10000

strSQL = "Select emp_no From AA_SAP_Numbers Order By emp_no"

'open the results
Set rst = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot)

rst.MoveFirst
Counter = counter + 1
rst.MoveNext
rst.Close
Generate_Number = Counter
End Function
Andy

Nov 13 '05 #1
2 5379
To really understand what your code is doing, just walk through this
with a pencil or pointing your finger. You have to realize that this
function STARTS from scratch and STOPS for each and every record in your
table/query.

Thus when the query containing this function is opened, for every
record resulting from the query this function is run and des the following:

1)counter is set to 10000;

2)it opens a record set of table AA_SAP_Numbers sorted by the emp_no;

3)It goes to the first record of that recordset;

4)It increases counter by 1;

5)It moves to the next record of the recordset;

6)It closes the recordset; and

7)The function returns the value of counter, ie, 10001.

If, for example, you have 500 records in the query, the above is
performed without variation 500 times, returning 10001 every single time.

In other words, the recordset you've opened serves no purpose. This
begs the question, why bother bogging down memory by opening a recordset
at all? It further begs the question, why even write a function? Just
type in 10001 as a field in your query builder for the query where
you're using this function.

Of course, that's not what you want. But it's important that you
examine your code and understand why it is what you've written performs
the seven steps I've outlined above.

Anderson wrote:
I have a table which has employee number. I have attempted to creat a
function whic will derive a unique number for each record how ever the
code below only returns 10,000 for all records. What I am doing wrong? I
am I right in saying that In assuming that I dont to loop since I am
returnign this for a every record in query.
Your help will be greatly appreciated.

Function Generate_Number (emp_no As Variant) As Variant
Dim strSQL As Variant
Dim rst As Recordset
Dim Counter As Variant
counter = 10000

strSQL = "Select emp_no From AA_SAP_Numbers Order By emp_no"

'open the results
Set rst = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot)

rst.MoveFirst
Counter = counter + 1
rst.MoveNext
rst.Close
Generate_Number = Counter
End Function
Andy

--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #2
Will creating a new field in the table that is a datatype of
AUTONUMBER - which will create a new unique number for each record,
work?

Anderson <a.********@lon donmet.ac.uk> wrote in message news:<co******* ***@canard.ulcc .ac.uk>...
I have a table which has employee number. I have attempted to creat a
function whic will derive a unique number for each record how ever the
code below only returns 10,000 for all records. What I am doing wrong? I
am I right in saying that In assuming that I dont to loop since I am
returnign this for a every record in query.
Your help will be greatly appreciated.

Function Generate_Number (emp_no As Variant) As Variant
Dim strSQL As Variant
Dim rst As Recordset
Dim Counter As Variant
counter = 10000

strSQL = "Select emp_no From AA_SAP_Numbers Order By emp_no"

'open the results
Set rst = CurrentDb.OpenR ecordset(strSQL , dbOpenSnapshot)

rst.MoveFirst
Counter = counter + 1
rst.MoveNext
rst.Close
Generate_Number = Counter
End Function
Andy

Nov 13 '05 #3

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

Similar topics

0
1544
by: Robert Kilroy | last post by:
Greetings, I've been working on a project for my church for a couple of weeks. We're going to be selling tickets to our events and we need to look for available seats in our hall. I have a query that returns to me all the seats that are available, which is great but the ideal solution would be to return X number of seats based on a seatnum (Integer).
0
1566
by: Lynn | last post by:
I have a query which shows start date and the last 4 digits of a person's SSN. I need sequential numbering of an assending start date yet desending last 4 digits of SSN (L4SSN). Using: RowNum: (Select Count (*) FROM as Temp WHERE . < .)+1 I can get close to what I want, but in case of ties, this just gives me the same number, i.e. 1, 2, 2, 4, 5, 6, 6, 6. I want to refer to desending order of L4SSN for sequential numbering in case of...
2
2310
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a simple "numbering records on a report" question. It is more complex than that. I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. ...
1
17825
by: systems analyst | last post by:
This is my modification on an original solution posted by Trevor Best (trevor@microprism.com) back in 1996. Insert the following code in a Module in your Access data base. Option Compare Database Option Explicit Dim mlngCounter As Long Function ZeroCounter() mlngCounter = 0
4
8841
by: James | last post by:
Hello there, Does anyone know how to create a sequential record number field in a query?? Thanks, James
14
12050
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.
1
1467
by: S. van Beek | last post by:
Dear reader, Is there a function to use in a query for numbering the records starting with one (1) and then second (2) and so on? Thanks for any help
0
1288
by: palmorek | last post by:
I am trying to build a macro in Excel for the purpose of authorizing checks. I am trying to figure out when the user is done entering their information they hit an enter button and the macro will assign an authorization number for that particular check. My delimma is sequential numbering. I found the following code. Public Function NEXTSeqNumber() Const sDEFAULT_PATH As String = "S:\Accounting\KPalmore" Const sDEFAULT_FNAME...
1
1690
by: wbw | last post by:
I have a database of products in which I have determined when the product sold. The table has two fields ITEM and SOLD. Each product’s first selling date may be different and may not have sold in every week. I need to assign a sequential numbering pattern since the product was first introduced. A new field, SEQNO, needs to be created to show 1 for the first time, 2 for the second time, 3 for the third time… etc. I would like to benchmark...
0
9672
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
9519
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
10000
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
9037
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
6779
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
5436
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.