473,791 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does a primary key become a negative number?

Ron
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?

TIA
ron
Nov 13 '05 #1
13 6542
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?


With Jet sure it is possible. There is even a technical reason for this:
the high order bit of the binary representation is interpreted as the
number being negative.

Autonumbers are known to make frantic jumps now and then. You cannot
rely on them climbing steadily.

Using your own incremential number is not too difficult. You must
confine all actions on such a table to routes via your code (either via
function calls or through forms that do the calculation of the new number)

Suppose you have a table Invoice, PK=invID (long). Have this in the
BeforeInsert handler of a form based on this table:

me!invID=nz(dma x("invID","Invo ice"),0)+1

This will yield 1 if there is no record yet, and the next free number if
there are records.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #2
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number


Don't. Just don't. Never use the PK as a tracking number the user
sees. Always keep the PK/FK as numbers in the background that nobody
sees. You will always eventually run into a situation where someone
wants to apply a schema for account numbers, enter a new invoice number
system based on the direction his small toe points, whatever. If you're
using as a joining column/field data tht is being read, it becomes a
difficult process to apply such changes to previous records. If you use
a properly normalized approach, you change an account number....once.

--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #3
i agree, I never use the autonumbers, it always ends in tears.
"Tim Marshall" <TI****@antarct ic.flowerpots> wrote in message
news:cn******** **@coranto.ucs. mun.ca...
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number


Don't. Just don't. Never use the PK as a tracking number the user sees.
Always keep the PK/FK as numbers in the background that nobody sees. You
will always eventually run into a situation where someone wants to apply a
schema for account numbers, enter a new invoice number system based on the
direction his small toe points, whatever. If you're using as a joining
column/field data tht is being read, it becomes a difficult process to
apply such changes to previous records. If you use a properly normalized
approach, you change an account number....once.

--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto

Nov 13 '05 #4
BE CAREFUL IF YOU CHOOSE TO USE me!invID=nz(dma x("invID","Invo ice"),0)+1.
If 2 users try to make an invoice at the same time, they will both get the
same ref number because their record has not yet been saved. Its better to
assign the number when you leave the record. This way it will look up the
number, assign it, save it and exit all at once. You could use a
docmd.runcomman d accmdsaverecord if you want, but I have seen some issues
with hard drive traffic that stops this command from occuring.

HTH
Paul

"Bas Cost Budde" <b.*********@he uvelqop.nl> wrote in message
news:cn******** **@news2.solcon .nl...
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is
not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?


With Jet sure it is possible. There is even a technical reason for this:
the high order bit of the binary representation is interpreted as the
number being negative.

Autonumbers are known to make frantic jumps now and then. You cannot rely
on them climbing steadily.

Using your own incremential number is not too difficult. You must confine
all actions on such a table to routes via your code (either via function
calls or through forms that do the calculation of the new number)

Suppose you have a table Invoice, PK=invID (long). Have this in the
BeforeInsert handler of a form based on this table:

me!invID=nz(dma x("invID","Invo ice"),0)+1

This will yield 1 if there is no record yet, and the next free number if
there are records.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea

Nov 13 '05 #5
Ron
Well, now I'm even *more* confused.

The first responder tells me the incremented autonumber field shouldn't be
used as a PK so gave me a nice routine to come up with my own PK. No prob.
However, you seem to be saying I shouldn't use the PK (I'd assume even the
one I come up with using this nice routine) as a user-visible account
number, invoice number, etc. So, then, I now need 2 numbers I come up with,
one to show the user and one to be the actual PK?

I feel like one of those lil' ducks at the arcade shooting gallery that
reverses directions with each direct hit. Boing, I'm going left, boing I'm
going right. Help! Somebody stop me!

ron

"Tim Marshall" <TI****@antarct ic.flowerpots> wrote in message
news:cn******** **@coranto.ucs. mun.ca...
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number


Don't. Just don't. Never use the PK as a tracking number the user
sees. Always keep the PK/FK as numbers in the background that nobody
sees. You will always eventually run into a situation where someone
wants to apply a schema for account numbers, enter a new invoice number
system based on the direction his small toe points, whatever. If you're
using as a joining column/field data tht is being read, it becomes a
difficult process to apply such changes to previous records. If you use
a properly normalized approach, you change an account number....once.

--
Tim
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto

Nov 13 '05 #6
Ron
Thanks Paul, that helped A LOT! Hadn't even gotten to the
"multi-user"thoughts yet, but yeah, there could be 2 to 3 users (max) trying
to save to the same file at the same time.

Thinking about it, though, I'll have a detail subform on my invoice form.
As the details are stored into their table, I need that linking InvoiceID,
so I won't be able to wait till they leave the invoice form to assign the
InvoiceID.

Anything wrong with putting a file on the BE that a routine can access
sooner to pull a number off for the next number up (for whatever file is
being added to) and then store the number+1 figure back into that field for
the next user? System can lock that file, do the math, store the new number
and unlock the file all pretty quickly. Wouldn't that solve the number+1
problem and still allow for multiple users? (Just thinking out in the open,
here)

Sorry for all the probably really basic questions.

TIA
ron

"Paul" <pz****@rogers. com> wrote in message
news:Z4******** ************@ro gers.com...
BE CAREFUL IF YOU CHOOSE TO USE me!invID=nz(dma x("invID","Invo ice"),0)+1.
If 2 users try to make an invoice at the same time, they will both get the
same ref number because their record has not yet been saved. Its better to assign the number when you leave the record. This way it will look up the
number, assign it, save it and exit all at once. You could use a
docmd.runcomman d accmdsaverecord if you want, but I have seen some issues
with hard drive traffic that stops this command from occuring.

HTH
Paul

"Bas Cost Budde" <b.*********@he uvelqop.nl> wrote in message
news:cn******** **@news2.solcon .nl...
Ron wrote:
Hi all

I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective files. I understand that sometimes a number will be missing, which is
not a
problem for my purposes I don't think, but how would it be negative? Can randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?


With Jet sure it is possible. There is even a technical reason for this:
the high order bit of the binary representation is interpreted as the
number being negative.

Autonumbers are known to make frantic jumps now and then. You cannot rely on them climbing steadily.

Using your own incremential number is not too difficult. You must confine all actions on such a table to routes via your code (either via function
calls or through forms that do the calculation of the new number)

Suppose you have a table Invoice, PK=invID (long). Have this in the
BeforeInsert handler of a form based on this table:

me!invID=nz(dma x("invID","Invo ice"),0)+1

This will yield 1 if there is no record yet, and the next free number if
there are records.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea


Nov 13 '05 #7
Ron wrote:
Well, now I'm even *more* confused.

The first responder tells me the incremented autonumber field shouldn't be
used as a PK so gave me a nice routine to come up with my own PK. No prob.
However, you seem to be saying I shouldn't use the PK (I'd assume even the
one I come up with using this nice routine) as a user-visible account
number, invoice number, etc. So, then, I now need 2 numbers I come up with,
one to show the user and one to be the actual PK?

I feel like one of those lil' ducks at the arcade shooting gallery that
reverses directions with each direct hit. Boing, I'm going left, boing I'm
going right. Help! Somebody stop me!


Roll your own number for the invoice number, have a unique index on it.
Use AutoNumber for the PK and relate all other table to that.

You can of course use your own rolled invoice number as the PK as this
is the candidate key for the record but there are drawbacks to doing
this, mostly to do with the number changing for some reason (usually
before the invoice is physically issued, then it should be frozen, set
in stone) lest you need to handle the dependant records or use cascades,
which IMHO are pretty hairy and invite major damage from a minor cock up.
--
This sig left intentionally blank
Nov 13 '05 #8
> I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a number will be missing, which is not a
problem for my purposes I don't think, but how would it be negative? Can
randomly created PK autonumber fields be negative? Any way for a PK,
autonumbered, *incremented* to be negative?


If you ask for random numbers you can definately get negatives - this
should be half the time. If you ask for incremented numbers, you
would have to specifically set them up to be able to make negatives (
seed = -x ).
Nov 13 '05 #9
Paul wrote:
BE CAREFUL IF YOU CHOOSE TO USE me!invID=nz(dma x("invID","Invo ice"),0)+1.
If 2 users try to make an invoice at the same time, they will both get the
same ref number because their record has not yet been saved. Its better to
assign the number when you leave the record. This way it will look up the
number, assign it, save it and exit all at once. You could use a
docmd.runcomman d accmdsaverecord if you want, but I have seen some issues
with hard drive traffic that stops this command from occuring.


I agree. Should have mentioned that this is for single user.

My multi user approach is to maintain a keys table, where the next
available number is stored. (There can be keys for any table prone to
this kind of inserts; my fields are tableName(text) nextFree(number ))
The BeforeInsert handler of a form locks this table (so the next attempt
will fail, code should pause and retry), gets the number, increases it
and writes it back. That in itself is a short action, will not halt
other users too much (up to 20 simultaneous insert-requests) and has the
number available at the beginning of the process, which is sometimes
highly wanted.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #10

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

Similar topics

15
2353
by: Claudio Grondi | last post by:
Let's consider a test source code given at the very end of this posting. The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in computers memory? Or does Python hide such implementation details that deep, that there is no way to get down to them? The test code below shows, that extracting bits from an integer value n is faster when using n&0x01 than when using n%2 and I...
13
1803
by: Ron | last post by:
Hi All, Okay, I've read previous suggestions about not showing the primary key to the user of forms. If a number is to be shown (let's say, customer number) it should be generated independently of the primary key (which is autonumbered and no dups). I think I've gotten that all accomplished. However, now how should I link files, or perform query's? Should these types of things be based on the customer number I generate or should I...
4
2317
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory as the sample. I have trouble translating those samples to working with data coming from my database, so I am hoping that someone could show me a sample of code that builds a tree from say a dataset. Many controls you can bind to a datasource,...
15
35518
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
3
5678
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works as designed or a bug ? Manuals say that the standby will inform the primary about the takeover but will not wait for acknowledgement, so the primary knows about whats going on. In my eyes primary should either switch to standby or shutdown...
3
3471
by: leah | last post by:
I encountered problem when i tried to create a primary key in an existing table which does not have one yet. There are too many records in it and it's hard to find out which one is 'duplicated'. I'm not sure whether, if there is any duplicate records in the table. How can i solve this problem? Thanks leah
20
5830
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including negative numbers into a separate sequence and ignore the (now empty) args list returned by getopt, but it would seem this is such a common requirement that there would be an option to treat a negative value as an argument. Note that this is only a...
34
2819
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
1
7781
by: santoshsri | last post by:
Hi All, My C# web application calls a webservice to process a report. It sends XMLs as parameter and in response gets an XML node which stores Binay datatype bin.base64. It makes an instance of the proxy class of webservice and makes a synchronous call to webservice GetReport() op. Here is the code snippet - *************************************************************************************** wbFELIP.wsZProcessReport.ProcessReport...
0
9666
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
10419
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
10147
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
9987
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
9023
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
7531
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
6770
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
5424
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
4100
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

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.