473,771 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resetting automatic File Number at start of new year

tdw
206 New Member
In my Orders database (which someone else created and I have been improving), when I enter a new order it generates a file number (i.e. 2007-0001) using an autonumber REC_ID field. I'll show you the code that it uses.
The following occurs upon a button click:
Expand|Select|Wrap|Line Numbers
  1. If Me![REC_ID] <> 0 And Me![FILE_NO] = "" Then
  2.     DoCmd.SetWarnings False
  3.         If Me![REC_ID] - 10493 < 10 Then ' Numeric Value 10493 is last value of rec_id upon year change for file_id renum
  4.         DoCmd.OpenQuery "FILE_NO_Update_New_000", acNormal, acEdit
  5.         GoTo Confirm_File_No_Creation
  6.         End If
  7.  
  8.         If Me![REC_ID] - 10493 < 100 Then
  9.         DoCmd.OpenQuery "FILE_NO_Update_New_00", acNormal, acEdit
  10.         GoTo Confirm_File_No_Creation
  11.         End If
  12.  
  13.         If Me![REC_ID] - 10493 < 1000 Then
  14.         DoCmd.OpenQuery "FILE_NO_Update_New_0", acNormal, acEdit
  15.         GoTo Confirm_File_No_Creation
  16.         End If
  17.  
  18.     DoCmd.OpenQuery "FILE_NO_Update_New", acNormal, acEdit
  19.  
Here are the update queries:
Expand|Select|Wrap|Line Numbers
  1. [b](FILE_NO_Update_New_000)[B/]
  2.  
  3. UPDATE SC_NEW SET SC_NEW.FILE_NO = Year(Date()) & "-000" & [REC_ID]-"10493"
  4. WHERE ((([Forms]![Add New Orders]![REC_ID])=[SC_NEW]![REC_ID]));
  5.  
  6. [b](FILE_NO_Update_New_00)[B/]
  7.  
  8. UPDATE SC_NEW SET SC_NEW.FILE_NO = Year(Date()) & "-00" & [REC_ID]-"10493"
  9. WHERE ((([Forms]![Add New Orders]![REC_ID])=[SC_NEW]![REC_ID]));
  10.  
  11. [b](FILE_NO_Update_New_0)[B/]
  12.  
  13. UPDATE SC_NEW SET SC_NEW.FILE_NO = Year(Date()) & "-0" & [REC_ID]-"10493"
  14. WHERE ((([Forms]![Add New Orders]![REC_ID])=[SC_NEW]![REC_ID]));
  15.  
  16. (FILE_NO_Update_New)
  17.  
  18. UPDATE SC_NEW SET SC_NEW.FILE_NO = Year(Date()) & "-" & [REC_ID]-"10493"
  19. WHERE ((([Forms]![Add New Orders]![REC_ID])=[SC_NEW]![REC_ID]));
  20.  
It seems pretty complex to me, but I understand it. The problem is that at the beginning of every year, we reset our file number back to 0001 (i.e. the first order of 2006 was 2006-0001, first order of 2007 was 2007-0001, etc.). The only way we know to accomplish this is to go into the code for the form and all three queries to change the REC_ID number being used in the calculations (the 10493 number in these examples). To know what to change it to, we have to find the highest REC_ID (the last order entered the previous year), which could be in either of two tables (one table of open orders: SC_OPEN, and another table of closed, or archived, orders: SC_ARCH). To do that, we have to manually open each table and look for ourselves. This can be complicated and very easy to badly screw up for non-programmers to try to accomplish, and it's not reasonable to expect that a programmer will always be available first thing in the morning on the first work day of the year to make these changes.

It would seem to me that there is simpler way, maybe even an automated way, to have our file number reset to 0001 at the beginning of each year. Any thoughts? Any suggestions? Should the whole process be reworked?
Apr 24 '07
38 4661
tdw
206 New Member
My pleasure.
Even if changing the function around fixes your error, I'd still use the code I posted in post #27 as it does the whole thing in one line for you. It even handles the first new record of a year.
I finally have a little time to get back to working on this. You suggest using the code
Expand|Select|Wrap|Line Numbers
  1. Val(Nz(Mid(DMax("[FILE_NO]","[SC_OPEN]","[FILE_NO] Like Format(Date(),'yyyy') & '*'"),6),"0"))+1
  2.  
I'm trying to understand what this line does and does not do so that I know what parts of my code it should replace. If I am understanding correctly, it will look for the highest existing file number with the format 'yyyy' & '*' (and this will properly generate the 2007-0123 format?) located in my SC_OPEN table, and add 1 to it. You say it will also recognize if there is no existing file number with the current year as the beginning of the file number, and start at zero?
I believe that I see where all of the above works in the code. Now, since the highest existing file number may actually be in the SC_ARCH table, I suppose I should copy the same line of code, changing the table to SC_ARCH? In which case I would still have to tell it to determine which of the two tables has the highest file number, prior to running the code above, so that it knows which line (referencing which table) to use and which to ignore?

Hit me on the head if I'm way off on my understanding of this! :-)
Jun 22 '07 #31
tdw
206 New Member
I suspect (Not sure as I don't really want to do a reverse engineering job on your 130+ lines of code) that the reason you had this problem is that you were using DLast() rather than DMax(). Simply changing that MAY resolve the issues with your current code.
You are correct, that did resolve it. However I am interested in your other suggestion. See below for more questions about it.
Jun 22 '07 #32
NeoPa
32,573 Recognized Expert Moderator MVP
I hadn't appreciated that you wanted to handle the max of both tables (begs the question why store the data in separate tables anyway?). Assuming that two tables are how you're doing this though, you will need some logic as per below :
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourSub()
  2.   Dim lngOpen As Long, lngMax As Long
  3.  
  4.   lngOpen = Val(Nz(Mid(DMax("[FILE_NO]", _
  5.                             "[SC_OPEN]", _
  6.                             "[FILE_NO] Like Format(Date(), 'yyyy\*')"), 6), _
  7.                    "0")) + 1
  8.   lngMax = Val(Nz(Mid(DMax("[FILE_NO]", _
  9.                            "[SC_ARCH]", _
  10.                            "[FILE_NO] Like Format(Date(), 'yyyy\*')"), 6), _
  11.                   "0")) + 1
  12.   If lngOpen > lngMax Then lngMax = lngOpen
  13. End Sub
Your code wouldn't necessarily need to be in a self-contained procedure as this example is. This is just an illustration of the concept for handling a situation like yours.
Jun 22 '07 #33
tdw
206 New Member
I hadn't appreciated that you wanted to handle the max of both tables (begs the question why store the data in separate tables anyway?). Assuming that two tables are how you're doing this though, you will need some logic as per below :
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourSub()
  2.   Dim lngOpen As Long, lngMax As Long
  3.  
  4.   lngOpen = Val(Nz(Mid(DMax("[FILE_NO]", _
  5.                             "[SC_OPEN]", _
  6.                             "[FILE_NO] Like Format(Date(), 'yyyy\*')"), 6), _
  7.                    "0")) + 1
  8.   lngMax = Val(Nz(Mid(DMax("[FILE_NO]", _
  9.                            "[SC_ARCH]", _
  10.                            "[FILE_NO] Like Format(Date(), 'yyyy\*')"), 6), _
  11.                   "0")) + 1
  12.   If lngOpen > lngMax Then lngMax = lngOpen
  13. End Sub
Your code wouldn't necessarily need to be in a self-contained procedure as this example is. This is just an illustration of the concept for handling a situation like yours.
Great, thanks! I appreciate it, and I will experiment with that even though it's working the other way. Always good to find shorter ways to do things!
The reason for two tables, though I'm not sure it's neccessary (I didn't write the original version of this database, just have been improving it and injecting it with steroids), is because once we complete a survey order, we archive it in the second table and delete it from the Open orders table. That way we can still search for data from past orders, but don't have it mixed in with the current ones.
Jun 23 '07 #34
NeoPa
32,573 Recognized Expert Moderator MVP
I'm glad that helps.
As far as the tables go, setting a flag and filtering the data would be another option. I can't say how appropriate that would be for you, as I'm not there and don't know your exact situation. I'll happily leave that to you :)
Jun 23 '07 #35
tdw
206 New Member
I'm glad that helps.
As far as the tables go, setting a flag and filtering the data would be another option. I can't say how appropriate that would be for you, as I'm not there and don't know your exact situation. I'll happily leave that to you :)
You know, I though of that too. However, if there are a whole lot of archived orders, would it slow down the form for viewing open orders, since it's opening the whole recordset before filtering it? I have a "edit order" button in my "View Open Orders" form that will open another form that lets the user edit that record. It filters the Edit form so that only the record currently displayed on the View form shows up for editing, yet it takes a while to load that Edit form. I have assumed that it is because it is really opening the entire table before filtering it down to the one record.
I guess that's really the only reason that I can see for having a separate table for the Archived orders.
Jun 26 '07 #36
NeoPa
32,573 Recognized Expert Moderator MVP
Whether or not the whole table is opened is generally down to your index design.
Simple rule of thumb :
If it can (by using one of your indexes) determine which records match your filter criteria, it will.
If you were to add an index on this flag field (not unique), then filtering should work fairly quickly.
At the end of the day, what works for you depends heavily on your requirements, but this could be considered. Obviously any change to the design or structure of a database is likely to involve the designer in some level of work (overhead).
Jun 28 '07 #37
tdw
206 New Member
Whether or not the whole table is opened is generally down to your index design.
Simple rule of thumb :
If it can (by using one of your indexes) determine which records match your filter criteria, it will.
If you were to add an index on this flag field (not unique), then filtering should work fairly quickly.
At the end of the day, what works for you depends heavily on your requirements, but this could be considered. Obviously any change to the design or structure of a database is likely to involve the designer in some level of work (overhead).
Ok, thanks. It would probably work pretty good to have a checkbox or other yes/no field in each record for closing out the order, but I better leave it as is for now and consider combining tables sometime in the future if we encounter anything that suggests the current setup has any problems relating to there being separate tables. While appending the data back into a single table would be easy, there would be the issue of "closing" individually a few thousand archived orders. :-)
Jul 2 '07 #38
NeoPa
32,573 Recognized Expert Moderator MVP
Sounds like a sensible compromise :)
Why take on extra work now, just to save you some potential work at a later date? It may never happen.
Jul 2 '07 #39

Sign in to post your reply or Sign up for a free account.

Similar topics

28
3389
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all images that have been used and are going to be closed. This is how ever no way to reduce the memory consumption. I have noticed , using the task manager, that garbage collector doesn't actually do any collections unless the computer becomes low...
4
2366
by: pjac | last post by:
I need assistance in creating an Automatic tracking number that appears in a textbox that looks like: 2004-001. The first part of the number is based on the year, the second part is generated from the last available number used. Also, the second part of the number needs to start over whenever a new year is started. for example: 2005-001. Any help would be greatly appreciated. Thanks, pjac
3
17338
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the common factor. Mal.
3
1959
by: deltauser2006 | last post by:
My database consists of information which is updated every quarter. Forms will compare data from the present quarter to quarters past. I need a way to make the database save a copy of itself every quarter and then be able to have a form refer to that data through a comparison. The historical data set would be created at the end of each quarter and lock in all the values from that quarter. For example this quarter (1st quarter 2006) I...
1
2719
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy for updating these tables via an ftp site: 1) Post a .mdb file to our ftp web site that contains the updated tables. My App code connects to the ftp site and gets the file name for any update files on the site. I already have code to do this...
3
1770
by: EllieT | last post by:
Hi all, I've been fiddling around with creating a new database (Access 2003, Windows XP) for work the past two weeks and am having trouble defining my own customized (yet still automatic) primary key. I have three different tables that need data inputted (Clients , Complaints , and Queries ) and need individual primary keys for each that are easily identifiable by the first letter and indicative year. I was hoping for something along...
10
1890
by: drrajnishpatel via AccessMonster.com | last post by:
i am trying to get "ID" an incremental number that simply resets to 1 each month in my "table1" thanks, -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/200808/1
14
19073
by: Tommy Jakobsen | last post by:
Hi. Is there a method in .NET that takes "year" as an argument and returns the total number of weeks in that year? For culture da-DK (Danish). Thanks in advance. Tommy.
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6712
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.