PC Review


Reply
Thread Tools Rate Thread

Auto-generate number

 
 
=?Utf-8?B?Y2tyb2dlcnM=?=
Guest
Posts: n/a
 
      19th Apr 2006
Hi! I've been reading previous posts and trying to set this up myself, but
keep getting various error messages I don't know how to fix. So, here's what
I'm trying to do:

- The first field that is filled in on a new form is a location ID (field
name "Location) ... which is a three character field. (i.e., "001", "002",
etc.)
- Once they've chosen their location, I need to automatically assign a log
number with the following format: "aaa-bbcc-ddd" where aaa=location ID;
bb=two-digit current year; cc=two-digit current month; and ddd=sequential
number based on the a/b/c values. For example, the first log number for
April 2006 for location "001" would be "001-0604-001", then "001-0604-002",
etc.; the first log number for April 2006 for location "002" would be
"002-0604-001", etc.

I'm fairly new to Access programming, so I need some help with coding the
event procedure to provide this log number ... and I'm not even sure which
event to assign the procedure to?

Thanks for your help!
Cindy
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      19th Apr 2006
You can use the DMax function to find out what the current highest number
available is. The code below assumes you are storing the dashes in your
data, bad idea, but commonly done. If you are not, just leave them out of
the code. The names are all made up, so you will have to change them to suit
your needs.

Dim varNextNum as Variant
Dim strLogPrefix as String

strLogPrefix = Me.txtLocation & "-" & Format(Date,"yymm") & "-"
varNextNum = DMax("[LOG_NUMBER]", "LogTable", _
Left([LOG_NUMBER,9) = '" & strLogPrefix & "'")
varNextNum = IIf(IsNull(varNextNum),1, Right(varNextNum,3) + 1)
Me.txtLogNumber = strLogPrefix & Format(varNextNum, "000")

"ckrogers" wrote:

> Hi! I've been reading previous posts and trying to set this up myself, but
> keep getting various error messages I don't know how to fix. So, here's what
> I'm trying to do:
>
> - The first field that is filled in on a new form is a location ID (field
> name "Location) ... which is a three character field. (i.e., "001", "002",
> etc.)
> - Once they've chosen their location, I need to automatically assign a log
> number with the following format: "aaa-bbcc-ddd" where aaa=location ID;
> bb=two-digit current year; cc=two-digit current month; and ddd=sequential
> number based on the a/b/c values. For example, the first log number for
> April 2006 for location "001" would be "001-0604-001", then "001-0604-002",
> etc.; the first log number for April 2006 for location "002" would be
> "002-0604-001", etc.
>
> I'm fairly new to Access programming, so I need some help with coding the
> event procedure to provide this log number ... and I'm not even sure which
> event to assign the procedure to?
>
> Thanks for your help!
> Cindy

 
Reply With Quote
 
=?Utf-8?B?Y2tyb2dlcnM=?=
Guest
Posts: n/a
 
      20th Apr 2006
That worked perfectly. Thank you so much, "Klatuu"!
Cindy

"Klatuu" wrote:

> You can use the DMax function to find out what the current highest number
> available is. The code below assumes you are storing the dashes in your
> data, bad idea, but commonly done. If you are not, just leave them out of
> the code. The names are all made up, so you will have to change them to suit
> your needs.
>
> Dim varNextNum as Variant
> Dim strLogPrefix as String
>
> strLogPrefix = Me.txtLocation & "-" & Format(Date,"yymm") & "-"
> varNextNum = DMax("[LOG_NUMBER]", "LogTable", _
> Left([LOG_NUMBER,9) = '" & strLogPrefix & "'")
> varNextNum = IIf(IsNull(varNextNum),1, Right(varNextNum,3) + 1)
> Me.txtLogNumber = strLogPrefix & Format(varNextNum, "000")
>
> "ckrogers" wrote:
>
> > Hi! I've been reading previous posts and trying to set this up myself, but
> > keep getting various error messages I don't know how to fix. So, here's what
> > I'm trying to do:
> >
> > - The first field that is filled in on a new form is a location ID (field
> > name "Location) ... which is a three character field. (i.e., "001", "002",
> > etc.)
> > - Once they've chosen their location, I need to automatically assign a log
> > number with the following format: "aaa-bbcc-ddd" where aaa=location ID;
> > bb=two-digit current year; cc=two-digit current month; and ddd=sequential
> > number based on the a/b/c values. For example, the first log number for
> > April 2006 for location "001" would be "001-0604-001", then "001-0604-002",
> > etc.; the first log number for April 2006 for location "002" would be
> > "002-0604-001", etc.
> >
> > I'm fairly new to Access programming, so I need some help with coding the
> > event procedure to provide this log number ... and I'm not even sure which
> > event to assign the procedure to?
> >
> > Thanks for your help!
> > Cindy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto generate invoice number peetersb@gmail.com Microsoft C# .NET 1 30th Dec 2008 12:30 PM
Re: How to generate a auto number or increment number strive4peace Microsoft Access Queries 1 19th Apr 2008 10:20 PM
Generate Auto Number Values jeanhurtado@gmail.com Microsoft Access 3 12th Mar 2007 09:41 PM
Auto generate number =?Utf-8?B?Q2hyaXM=?= Microsoft Access VBA Modules 2 6th Oct 2005 06:27 PM
Auto Generate Number =?Utf-8?B?QW5u?= Microsoft Access Reports 3 16th Dec 2004 05:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:35 PM.