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 help please?



 
 
Thread Tools Display Modes
  #1  
Old May 10th, 2009, 04:42 AM posted to microsoft.public.access.tablesdbdesign
June7
external usenet poster
 
Posts: 68
Default auto increment help please?

No, cannot auto create this number in table design. I have a similar
situation. Here is code similar to what I use. Modified for you because I
use 4-digit year.
[code]Public Function MyID()

MyID = DLast("ID", "Problem11", "Right(ID,2)=" & Right(DatePart("yyyy",
Now), 2))
If Len(MyID) 1 Then
MyID = Format(Left(MyID, 4) + 1, "0000") & "-" & Right(DatePart("yyyy",
Now), 2)
Else
MyID = "0001-" & Right(DatePart("yyyy", Now), 2)
End If

"norm" wrote:

Is it possible to auto increment a field in a table based on the last 2
digits of year? I am creating a small database for a towing company, and I
need to assign each tow job a specific (unique) ticket number. But I need it
to be based on year for example:

tow
0001-09
0002-09
0003-09
0001-10
0002-10
0003-10
etc....
Is this possible in table design?

Thanks in advance for any help!

Norm

  #2  
Old May 10th, 2009, 05:37 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default auto increment help please?

On Sat, 9 May 2009 20:42:01 -0700, June7
wrote:

No, cannot auto create this number in table design. I have a similar
situation. Here is code similar to what I use. Modified for you because I
use 4-digit year.
[code]Public Function MyID()

MyID = DLast("ID", "Problem11", "Right(ID,2)=" & Right(DatePart("yyyy",
Now), 2))
If Len(MyID) 1 Then
MyID = Format(Left(MyID, 4) + 1, "0000") & "-" & Right(DatePart("yyyy",
Now), 2)
Else
MyID = "0001-" & Right(DatePart("yyyy", Now), 2)
End If


June, I'd use DMax rather than DLast - DLast returns the last record in *disk
storage order*, and that order can be anything that the program finds
convenient. It's basically a random record.
--

John W. Vinson [MVP]
 




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 10:45 AM.


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