Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / August 2005

Tip: Looking for answers? Try searching our database.

AutoNumbering

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry Baxley - 11 Aug 2005 09:41 GMT
I have a text field PO# which is my key field.  Every month the PO# changes  
(i.e. OCT 2006 - PO-FY601-001, NOV 2006  PO-FY602-001,002,003 etc).  I have
an append query the I run to reset the FY6## every month.  Is there any way
to automatically increase the last three digits?

Thanks

Larry
Nikos Yannacopoulos - 11 Aug 2005 12:28 GMT
Larry,

If I understand correctly, your fiscal year starts Oct.01? So now it is
FY511?

Are you entering PO's manually through a form? If yes, then it's just a
question of a VBA function to calculate the next "number"; use the
function in the form control's Default Value property, and it will fdo
the job. Now, the function:

Function Next_PO_No() As String
Dim vThisMonth As Integer
Dim vFM As String
Dim vFY As String
Dim vLast As String
Dim vPrefix As String
vThisMonth = Month(Date)
Select Case vThisMonth
Case 1 To 9
    vFY = Right(Year(Date), 1)
    vFM = Format(vThisMonth + 3, "00")
Case 10 To 12
    vFY = Right(Year(Date) + 1, 1)
    vFM = Format(vThisMonth - 9, "00")
End Select
vPrefix = "PO-FY" & vFY & vFM & "-"
vLast = DMax("PONumber", "tblPurchaseOrders", _
    "Left([PONumber],9)='" & vPrefix & "'")
Next_PO_No = vPrefix & Format(Val(Right(vLast, 3)) + 1, "000")
End Function

HTH,
Nikos
l_bax@hotmail.com - 14 Aug 2005 11:32 GMT
Sorry, I'm new at this game.  What exactly do you mean by the form
control's Default Value property?  I've inserted the code into OnOpen &
BeforeUpdate and can't get it to work.

TIA

> Larry,
>
[quoted text clipped - 29 lines]
> HTH,
> Nikos
Nikos Yannacopoulos - 30 Aug 2005 10:34 GMT
Larry,

Hope you're still out there, I've been off for two weeks.

The OnOpen event, which you tried, is a form event, not an event of the
particular control (invoice number textbox). Presumably, the
BeforeUpdate one was also the form's BeforeUpdate - but even if it were
the control's BeforeUpdate event, it's still not the right one. While in
form design, select the invoice number textbox, display its properties,
go to tab Events, put the cursor next to Default Value and type (or
paste) the function name, Next_PO_No(). The function itself (code in my
previous post) must be pasted in a general module (Modules, New in the
database window to create one, if you don't have any yet).

HTH,
Nikos

> Sorry, I'm new at this game.  What exactly do you mean by the form
> control's Default Value property?  I've inserted the code into OnOpen &
> BeforeUpdate and can't get it to work.
>
> TIA
Jeff Boyce - 11 Aug 2005 13:11 GMT
Larry

Just an observation...

If your field contains something like "OCT 2006 - PO-FY601-001" from your
post, your table structure might benefit from a bit more normalization.  It
appears you have multiple facts embedded in a single field.

If so, you would need to either "parse out" information (e.g., Fiscal Year)
to use it, or would have to redundantly store a field of "Fiscal Year" data
to use it (e.g., show all POs from FY 06).

One of the early steps in normalization can be paraphrased as "one field,
one fact".  You could store your combined facts in separate fields, and use
a query to concatenate them together into the string you provided as an
example "PO#".

Regards

Jeff Boyce
<Access MVP>
> I have a text field PO# which is my key field.  Every month the PO# changes
> (i.e. OCT 2006 - PO-FY601-001, NOV 2006  PO-FY602-001,002,003 etc).  I have
[quoted text clipped - 4 lines]
>
> Larry
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.