Solved

Setting Serial numbers back to 1 (automatically) at the beginning of Year.

Posted on 2001-06-04
8
153 Views
Last Modified: 2010-05-02
I developed a few Databases (msaccess) with vb frontends. Every year I manually set the tracking numbers to 001.  However, I will be leaving my position in the near future and I want to leave the company with programs that need no user intervention if possible.  The serial number is 3 digits long, show the leading 0's (ex:001).  Can someone lead me in the right directon.  Everytime I think I have the answer, there is a loop hole somewhere.

Your assistance is greatly appreciated.

Vannms
0
Comment
Question by:vannwms
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 3

Accepted Solution

by:
RodStephens earned 50 total points
ID: 6152611
I'm not sure which of this you need help with, but I can at least help with printing leading zeros.

    Format$(the_value, "000")
0
 
LVL 3

Expert Comment

by:wpsjr1
ID: 6152655
Dim i As Long
i = 1
Debug.Print Right$("00" & CStr(i), 3)
0
 

Author Comment

by:vannwms
ID: 6152656
Thank you for the formating information, but I want to reset the tracking number to 001 on the first of the year.

Your assistance is appreciated.

vannwms
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Expert Comment

by:PBuck
ID: 6152665
I would suggest having a procedure that checks for first day of year (Julian date of 0 as an example).  Place this code within your form_load event or some where similiar where it will be ran somewhere up front.

To top it off, place some sort of key value within your registry or INI file that flags that you have done this for the current year.  This way, if your user gets on the for the first time this year on Jan 3 - your flag for the current year should be false - set the flag to true and change the counter to 001.

Hope this helps some.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6152715
Hi, Create a small program to read the value of current number (from registry/ files/ database?), let the program run at Startup/ Windows boot, or set in registry:

(Create a string value in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run)


Just let the program read from the source from Starting windows, determine the value, if value Not equally to 0 and date = diedline (first day of the year), set it to 0, save a string/ key to stop detecting next time, or remove the string in Startup/ Windows boot, or set in registry.

Hope this give you an idea..
0
 
LVL 4

Expert Comment

by:PBuck
ID: 6152744
Remember you need to take into consideration whether or not people will be starting this application on the first day of every year.  Will the Julian date 0 be on a Saturday when nobody works - or is this program a batch type application?
0
 
LVL 3

Expert Comment

by:wpsjr1
ID: 6153545
Store the year to a registry key on initial installation.  Then each time the application is run check the current year. If it is not the same as the stored year then reset the tracking number.

Private Sub Form_Load()
  Dim sCurrentYear As String
 
  sCurrentYear = Year(Now)
  If GetSetting("app", "sec", "curryear", "") <> sCurrentYear Then
    If MsgBox("Reset tracking numbers?", vbOKCancel Or vbQuestion) = vbOK Then
      SaveSetting "app", "sec", "tracking", "001"
      SaveSetting "app", "sec", "curryear", sCurrentYear
    End If
  End If
End Sub

' or appropriate code to save tracking to the DB instead of SaveSetting.
0
 

Author Comment

by:vannwms
ID: 6216028
Reset the tracking number was my biggest problem, but since none of the other ideas worked, I did use your solution for my formating problem.

Thanks Rod

vannwms
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question