473,771 Members | 2,394 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
NeoPa
32,573 Recognized Expert Moderator MVP
Not off the top of my head no, but it might be interesting to know which line it appears on? Otherwise I can wait to see where you get to.
May 20 '07 #11
tdw
206 New Member
Not off the top of my head no, but it might be interesting to know which line it appears on? Otherwise I can wait to see where you get to.
It appears that it is occurring on the first DCount line. I threw in a message box between every step so I could see where it was giving me the error message "you canceled the previous operation". The last message box I get before the error is "Step 2: Dim variables as integers accomplished"
Expand|Select|Wrap|Line Numbers
  1. Private Sub Create_Order_File_Structure_Click()
  2. On Error GoTo Err_Create_Order_File_Structure_Click
  3.  
  4. '   Yes No Box
  5.     Dim Msg, Style, Title, Response
  6.     Msg = "Are you sure you want to Create this new Open Order?"    ' Define message.
  7.     Style = vbYesNo   ' Define buttons.
  8.     Title = "Create Order"    ' Define title.
  9.     Response = MsgBox(Msg, Style, Title)
  10. If Response = vbYes Then    ' User chose Yes
  11.  
  12.     RunCommand acCmdSaveRecord
  13.  
  14. MsgBox ("Step 1: save record accomplished")
  15.  
  16. Dim stHighest As Integer
  17. Dim stHighOpen As Integer
  18. Dim stHighArch As Integer
  19.  
  20. MsgBox ("Step 2: Dim variables as integers accomplished")
  21.  
  22.     '   Check to see if this is the first order of the year
  23.     If DCount("[FILE_NO]", "SC_OPEN", "Left([FILE_NO], 4) = Year(DATE)") < 1 Then
  24.  
  25. MsgBox ("Step 3a: first order of year in open? found true")
  26.  
  27.         If DCount("[FILE_NO]", "SC_ARCH", "Left([FILE_NO], 4) = Year(DATE)") < 1 Then
  28.             Me.FILE_NO = Year(DATE) & "-0001"   '   Reset file number to 1
  29.  
  30. MsgBox ("Step 3b: first order of year in arch? found true. accomplished")
  31.  
  32.         End If
  33.     Else
  34.  
  35. MsgBox ("Step 3c: not found to be first order of year")
  36.  
  37.         '   Find the highest file number for the current year from both tables
  38.         stHighOpen = DLast("Right([FILE_NO], 4)", "SC_OPEN", "Left([FILE_NO], 4) = Year(DATE)")
  39.  
  40. MsgBox ("Step 4a: find highest number in open accomplished")
  41.  
  42.         stHighArch = DLast("Right([FILE_NO], 4)", "SC_ARCH", "Left([FILE_NO], 4) = Year(DATE)")
  43.  
  44. MsgBox ("Step 4b: find highest number in arch accomplished")
  45.  
  46.         '   Pick the one that is highest
  47.             If stHighOpen < stHighArch Then
  48.                 stHighest = stHighArch
  49.  
  50. MsgBox ("Step 4c: found open to be lower than arch")
  51.  
  52.             Else
  53.                 stHighest = stHighOpen
  54.  
  55. MsgBox ("Step 4d: found open to be higher than arch")
  56.  
  57.             End If
  58.  
  59.         '   Create new file number
  60.         Me.FILE_NO = Year(DATE) & "-" & stHighest + 1
  61.  
  62. MsgBox ("Step 5: add 1 to highest number accomplished")
  63.  
  64.     End If
  65.  
  66. Confirm_File_No_Creation:
  67.     DoCmd.SetWarnings True
  68.     MsgBox ("The File Number Has Been Created For The Order")
  69.  
May 20 '07 #12
NeoPa
32,573 Recognized Expert Moderator MVP
Sorry to take so long.
I couldn't see for looking :
Left([FILE_NO], 4) is alpha and Year(DATE) is numeric.
Try instead :
Expand|Select|Wrap|Line Numbers
  1. If DCount("[FILE_NO]", "SC_OPEN", "Left([FILE_NO], 4) = Format(DATE, 'yyyy')") < 1 Then
May 21 '07 #13
tdw
206 New Member
Sorry to take so long.
I couldn't see for looking :
Left([FILE_NO], 4) is alpha and Year(DATE) is numeric.
Try instead :
Expand|Select|Wrap|Line Numbers
  1. If DCount("[FILE_NO]", "SC_OPEN", "Left([FILE_NO], 4) = Format(DATE, 'yyyy')") < 1 Then
I made the changes but I still get the same message "you canceled the previous operation". The message appears at the same place as before. I've tried looking through this forum, and the microsoft site, but haven't found anything even close to resembling this problem.
May 21 '07 #14
tdw
206 New Member
I made the changes but I still get the same message "you canceled the previous operation". The message appears at the same place as before. I've tried looking through this forum, and the microsoft site, but haven't found anything even close to resembling this problem.
By the way, the form that runs this code does not use either the SC_OPEN nor the SC_ARCH tables as it's data source. Could this be a cause of the problem? If so, I'll feel really stupid for not mentioning it before!
May 21 '07 #15
NeoPa
32,573 Recognized Expert Moderator MVP
By the way, the form that runs this code does not use either the SC_OPEN nor the SC_ARCH tables as it's data source. Could this be a cause of the problem? If so, I'll feel really stupid for not mentioning it before!
No. They should be entirely independant of each other.
I'm not sure what your problem is if it's not that I'm afraid.
I may get another chance to look later, but life's very busy ATM I'm afraid.
May 22 '07 #16
tdw
206 New Member
life's very busy ATM I'm afraid.
Same here! :-) I'll have to wait till later (or tomorrow) to play with Access anyway.
May 22 '07 #17
NeoPa
32,573 Recognized Expert Moderator MVP
Same here! :-) I'll have to wait till later (or tomorrow) to play with Access anyway.
That's fine then. We both agree to give the other plenty of time to respond :D
May 22 '07 #18
tdw
206 New Member
I made the changes but I still get the same message "you canceled the previous operation". The message appears at the same place as before. I've tried looking through this forum, and the microsoft site, but haven't found anything even close to resembling this problem.
Ok, I finally have some more time to devote to this. Just waking this sleeping thread back up. :-)
May 29 '07 #19
NeoPa
32,573 Recognized Expert Moderator MVP
Ok, I finally have some more time to devote to this. Just waking this sleeping thread back up. :-)
I've got a couple of potentially sticky days ahead. I had a quick look through, but nothing jumped out as the problem. If I don't think of anything by Thursday bump it up again for me please. I'll try to look at it more deeply before then if I get a chance though.
May 30 '07 #20

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...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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

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.