Home | Advertising Info6 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Monday, May 13, 2024  

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - Code Samples
 PowerASP Code Help Area : Classic ASP - Code Samples
Subject Topic: Pad With Leading 0’s Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Bullschmidt
Newbie
Newbie
Avatar

Joined: July/06/2004
Location: United States
Online Status: Offline
Posts: 12
Posted: July/06/2004 at 1:30am | IP Logged Quote Bullschmidt

To pad with leading 0's up to 4 digits:
varFld = Right("0000" & varFld, 4)

- - - - -


To generate the next invoice number using as an example 0003 (i.e. there are leading zeros):

Use max in a totals SQL statement:
strSQL = "SELECT Max(tblInv.InvID) AS InvIDMax FROM tblInv"

And then add one to the one record's one field:
NewID = objRS("InvIDMax") + 1

And then add padding:
NewID = Right("0000" & NewID, 4)



__________________
J. Paul Schmidt, Freelance ASP Web Developer
www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Sample (Freely Downloadable)
Back to Top View Bullschmidt's Profile Search for other posts by Bullschmidt Visit Bullschmidt's Homepage
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Posts: 137
Posted: July/06/2004 at 12:35pm | IP Logged Quote cwilliams

Grabbing the next number in the database like that won't always work.

That is if your number ID field is a autonumber or auto increment field which it would most likely be.

For example when using MSACCESS if by chance the next number has been created and then deleted... (slim chance but it can happen)

If you use the method listed above you will get the wrong number because access will skip the one it deleted...  etc etc

I dont think that is an issue with SQL server though

There are also other scenarios when that will fail and get the wrong number.. like under multi user scenarios where another user might create a record right after you grab what you think is the next number... and before you actually create a record.

The best way to get the upcoming record number is of course to get it with your recordset at the same time you create that new record.

Your padding example though is clever and simple.



Edited by cwilliams on July/06/2004 at 3:08pm


__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other posts by cwilliams
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2024 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages help tutorial how to ASP Help ASP Tutorials ASP Programming ASP Code - ASP Free CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com