A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Auto Increment for non integer ?



 
 
Thread Tools Display Modes
  #1  
Old August 12th, 2009, 05:04 AM posted to microsoft.public.access.tablesdbdesign
saleemMSMS
external usenet poster
 
Posts: 1
Default Auto Increment for non integer ?

hi i have a table called invoice. the primary key supposed to be not only a
number, but also a string. i thought of making the primary key as follows.
INV001, INV002 etc. is there a way to auto increment such string values ? if
yes how to ? if no, can anyone suggest me a way of having a sequential yet
string attached primary key ?
thanx

  #2  
Old August 12th, 2009, 05:26 AM posted to microsoft.public.access.tablesdbdesign
Tom van Stiphout[_2_]
external usenet poster
 
Posts: 1,653
Default Auto Increment for non integer ?

On Tue, 11 Aug 2009 21:04:01 -0700, saleemMSMS
wrote:

This is a FAQ. You should have no problem finding related posts in
groups.google.com. You will find:
* It often does not make sense to assign meaning to a PK - it
typically is used for internal bookkeeping and not exposed to users
* You can format a number in your pattern:
select "INV" & Format(myPkValue, "000") from myTable
(of course you replace myObjectNames with yours, and keep your fingers
crossed you never have more than 999 invoice numbers.

-Tom.
Microsoft Access MVP


hi i have a table called invoice. the primary key supposed to be not only a
number, but also a string. i thought of making the primary key as follows.
INV001, INV002 etc. is there a way to auto increment such string values ? if
yes how to ? if no, can anyone suggest me a way of having a sequential yet
string attached primary key ?
thanx

  #3  
Old August 12th, 2009, 01:39 PM posted to microsoft.public.access.tablesdbdesign
Klatuu
external usenet poster
 
Posts: 7,074
Default Auto Increment for non integer ?

If the string part will always be INV, why include it in the table? It can
always be added to the number for display on forms and reports. And, do not
use an autonumber field for the numbers. Autonumber fields should only be
used as surrogate keys for relating tables.

It increment a numeric field, use the form's Current event to find the
current highest number and add 1 to it.

If Me.NewRec then
Me.txtInvNo = Nz(DMax("[INV_NO]","[tblInvoice]"), 0) + 1
End If
--
Dave Hargis, Microsoft Access MVP


"saleemMSMS" wrote:

hi i have a table called invoice. the primary key supposed to be not only a
number, but also a string. i thought of making the primary key as follows.
INV001, INV002 etc. is there a way to auto increment such string values ? if
yes how to ? if no, can anyone suggest me a way of having a sequential yet
string attached primary key ?
thanx

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.