473,441 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

Reset Increment number on new month

Kd
I have the OrderNo set as the following
Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") &
"-"Format([OrderNo],"000")+1
This works great until
I get to a new month and need the numbers to reset like the following
example
512-001
Anybody have any thoughts to point me in the right direction,got stuck
with making updates to someone elses created database and getting
frustrated.

Any thoughts or ideas would be appreciated
Thank you

Nov 23 '05 #1
6 5984
On 21 Nov 2005 20:40:57 -0800, "Kd" <ke******@yahoo.com> wrote:
I have the OrderNo set as the following
Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") &
"-"Format([OrderNo],"000")+1
This works great until
I get to a new month and need the numbers to reset like the following
example
512-001
Anybody have any thoughts to point me in the right direction,got stuck
with making updates to someone elses created database and getting
frustrated.

Any thoughts or ideas would be appreciated
Thank you


The example you gave must be from memory because that won't quite work, but in
any case, I think the most straightforward approach is to simply have a table
with month and year as fields in the key, and a NextSuffix field that gets
incremented for each new record.

I would not use existing records to determine the last number in use because a
deleted record could have its number reused, and that's bad for any kind of
auditing or reconciliation you have to do. I would also not just keep a
single counter and reset it because you may at some point need to insert a
record with a prior effective date.

The function to get a suffix value for a new record could be something like
the following (untested)...

Public Function NewSuffixInMonth( _
SuffixTable As String, _
RecDate As Date _
) As String
Dim lngResult As Long

On Error Goto Err_Catch

Dim dbs As DAO.Database
Set dbs = CurrentDB()

Dim qdf As DAO.Querydef
Set qdf = dbs.CreateQuerydef("")
qdf.SQL = "SELECT * FROM [" & SuffixTable & "] " & _
"WHERE [" & SuffixTable & "].YearNum = prm_YearNum AND " & _
"[" & SuffixTable & "].MonthNum = prm_MonthNum

Debug.Assert qdf.Parameters.Count = 2

qdf.Parameters!prm_YearNum = DatePart("yyyy", RecDate)
qdf.Parameters!prm_MonthNum = DatePart("m", RecDate)

Dim rstSuffix As DAO.Recordset
Set rstSuffix = qdf.OpenRecordset(dbOpenDynaset)

If rst.RecordCount > 0 Then
rst.Edit
lngResult = rstSuffix!SuffixNum + 1
Else
rst.AddNew
lngResult = 1
End If

rst!SuffixNum = lngResult
rst.Update

Proc_Final:

If Not rst Is Nothing Then
On Error Resume Next
rst.Close: Set rst = Nothing
On Error Goto 0: Err.Clear
End If
Set qdf = Nothing
Set dbs = Nothing

NewSuffixInMonth = Format(lngResult, "000")
Exit Function

Err_Catch:
MsgBox Err.Description
Resume ProcFinal

End Function
Nov 23 '05 #2
Kd wrote:
I have the OrderNo set as the following
Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") &
"-"Format([OrderNo],"000")+1
This works great until
I get to a new month and need the numbers to reset like the following
example
512-001
Anybody have any thoughts to point me in the right direction,got stuck
with making updates to someone elses created database and getting
frustrated.

Any thoughts or ideas would be appreciated
Thank you


How is OrderNo being incremented curretly?

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 23 '05 #3
Kd


=DMax("[OrderNo]","[tblOrder]")+1

Nov 23 '05 #4
Kd wrote:
=DMax("[OrderNo]","[tblOrder]")+1


So you simply need to add a criteria to the DMax statement that will cause it to
start over each month.

=Nz(DMax("[OrderNo]","[tblOrder]", Format(RecordDate, "yyyymm") = Format(Date(),
"yyyymm")), 0)+1

Obviously you need a field like [RecordDate] in your table that provides a
timestamp for when the record was created. Given your current setup I assume
you have such a field.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 23 '05 #5
Kd
Yes I have a field in table OrderDate
Thank you for your input

Nov 23 '05 #6
Kd
Ok have Order number working fine in form
but I would like this number511-001
to be the Pk on the order table

Nov 25 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ryan P. Kennedy | last post by:
Reset the Identity Increment Hello: I have a table with a bigint type column (field) that has an identity seed of 1 and an identity increment of 1. The column is the primary key for the...
0
by: Earl Anderson | last post by:
KB Article Q140908 provided the following function to create an Auto Incrementing Counter: Function Next_Custom_Counter () On Error GoTo Next_Custom_Counter_Err Dim MyDB As Database Dim...
16
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
9
by: boliches | last post by:
I have a seperate table to generate consecutive numbers. Using "Dmax" to find the largest number to increment . My problem is that I want the number to begin at 1000 at the start of each month,...
2
by: DerekF | last post by:
Reset the Identity Increment -------------------------------------------------------------------------------- Reset the Identity Increment Hello: I have a table with a bigint type column...
4
by: rdsandy | last post by:
Hi, I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who...
3
by: Wayne L | last post by:
Ok now everyone has mentioned not to use auto number if it means anything to the user. My application uses the auto number for exporting only. I append the mastertbl column with my starting number of...
12
by: Coni | last post by:
Hi All, I am working in Access to print Invoices. On each invoice there is a line number column which is a field to number each line for a product purchase. I would like to know if there is a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.