473,408 Members | 2,734 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,408 software developers and data experts.

Reset consecutive numbers at start of month

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, deleteing the previous numbers created in the table.

Table : tblNewNum
Field: NewNum

Januarys Contents of field would read ie. 1000, 1001, 1002, 1003 etc

How can I get the first number generated at the start of each month to be 1000?

Hope this makes sense and that there is a solution, I am using MS Access 2000 with XP.

Regards
Feb 2 '07 #1
9 4426
Rabbit
12,516 Expert Mod 8TB
What's your experience with coding?
Feb 2 '07 #2
What's your experience with coding?
Limited, but am learning as I go along. I am not fazed by a bit of difficult coding even if I dont fully understand it. I tend to search the web for answers to my problems as and when I come across one.

Do you need any of the code I am using to generate the consecutive numbers?
Feb 2 '07 #3
Rabbit
12,516 Expert Mod 8TB
I don't need the code you use to generate the number, I think I know what you did for that.

To do what you want, you're gonna have to run a check.

Expand|Select|Wrap|Line Numbers
  1. If Day(Date()) = 1 Then
  2.   ' Check to see if you've already run this for the month.
  3.   ' If No, then delete all records and insert one record with the value 999
  4. End If
  5.  
To check if you've already run the delete query for the month you'll have to store the last month you ran the delete query in either the same table or in a different table.

Let me know if you need any more specifics.
Feb 2 '07 #4
Sorry if I am being a bit thick! But if you could explain a little more I would be very grateful. It sounds as if you understand what I am trying to achieve, it is just the how and where.

Cheers.
Feb 2 '07 #5
Rabbit
12,516 Expert Mod 8TB
What's you want to do is make another table that has one field and one record. The record will basically be the number of the month when the other table was last cleared.

So what you'll have is 2 tables.

tbl_AutoNumber
tbl_Month

Now in the same place that you generate the Auto Number, before everything else, you need to check if 1) It's the first of the month and 2) If the table has been cleared yet. This is checked by seeing if the month in the table is the same as the month of the current date.

If both of these are true, then it deletes all records from the 2 tables and inserts the value 999 into tbl_AutoNumber and the value of the current month into tbl_Month.

Expand|Select|Wrap|Line Numbers
  1. If Day(Date()) = 1 Then
  2.   If DLookup("LastMonth", "tbl_Month") = Month(Date()) Then
  3.     DoCmd.SetWarnings False
  4.     DoCmd.RunSQL "Delete * From tbl_Month"
  5.     DoCmd.RunSQL "Delete * From tbl_AutoNumber"
  6.     DoCmd.RunSQL "Insert Into tbl_Autonumber Values (999)"
  7.     DoCmd.RunSQL "Insert Into tbl_Month Values (" & Month(Date()) & ")"
  8.     DoCmd.SetWarnings True
  9.   End If
  10. End If
  11.  
Feb 2 '07 #6
Have tried the code but am getting a "Type Mismatch" warning re:

If DLookup("LastMonth", "tbl_Month") = Month(Date()) Then ........

It appears the error involves the Month(Date())

What have I forgotten to do? Is the Month(Date()) looking for the number of month ie. "1" or the word "January" in tbl_Month, or is it something else that I should have done?

Thanks
Feb 3 '07 #7
Further assistance please:

I thinh I have sorted the previous problem, thnank. But have now encountered a further one.
This was working but now, for some reason, does not:

It is the consecutive number using DMax to look up the greatest number used last! It has stopped looking for the greater number and each time I run the code I get the number generated : 1000 (it would actually read "02BP1000")

Here is the complete code I am using:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim strTable As String
  3. Dim Month As String
  4. Dim Month2 As String
  5.  
  6. Month1 = Format([Date], "mm")
  7.  Month2 = Month1 - 1
  8.   Me.txtBrokerName = Me.cboBrokersID
  9.   Me.txtDealNo = Me.DealNo
  10.   Broker = Me.txtBrokerName
  11.   strTable = "tblNewDealNum" + Broker
  12.   strNum = Broker + "QiNum"
  13.  
  14.    If IsNull(DMax(strNum, strTable)) Then
  15.              SQLtxt2 = "INSERT INTO " & strTable & " (" & strNum & ")  SELECT 999"
  16.                    DoCmd.RunSQL (SQLtxt2)
  17.                                 End If
  18.  
  19.  If Day(Date) <= 31 Then
  20.   If DLookup("LastMonth", "tblCheckMth") = Month2 Then
  21.     DoCmd.SetWarnings False
  22.     DoCmd.RunSQL "Delete * From tblCheckMth"
  23.     DoCmd.RunSQL "Delete * From " & strTable
  24.     DoCmd.RunSQL "Insert Into " & strTable & " Values (999)"
  25.     DoCmd.RunSQL "Insert Into tblCheckMth Values (" & Month1 & ")"
  26.     DoCmd.SetWarnings True
  27.   End If
  28. End If
  29.  
  30. Num = DMax(strNum, strTable) 'This does not appear to work!
  31.         NewNum = Num + 1
  32.         Me.txtDealNo = "" & Month1 & "" & Broker & "" & NewNum & " "
  33.         Me.DealNo = Me.txtDealNo
  34.         strMsg = Me.DealNo
  35.         Me.txtBrokerUpdate = Me.txtBrokerName
  36.  
  37. MsgBox "Ticket Number " & strMsg & "."
  38.     SQLtxt1 = "INSERT INTO " & strTable & " (" & strNum & ")  SELECT " & NewNum
  39.          DoCmd.RunSQL (SQLtxt1)
  40.             DoCmd.GoToRecord acDataForm, "frmAddDeal", acNewRec
  41.                 cboBrokersID.SetFocus
  42.  
Feb 3 '07 #8
Sorry!

May have sorted it !!!!

I had the table "QiNUm" set to "Text" I have changed it to "Number" and it seems to be working.


Big thanks for all your help.

Regards
Feb 3 '07 #9
NeoPa
32,556 Expert Mod 16PB
Sorry!

May have sorted it !!!!

I had the table "QiNUm" set to "Text" I have changed it to "Number" and it seems to be working.


Big thanks for all your help.

Regards
Just an idea, and I know it's a bit late, but if the data you get is to add a new value into your main table and that includes an indicator for the month, then you can use the same concept to get the value you need without recourse to a separate table at all.
As an illustration, say your main table has items with a PK made up of (including would work too, but for simple illustration...) MMMXXXX where MMM ==> 3 letters of Month & XXXX ==> 4 digit number starting from 1000.
Expand|Select|Wrap|Line Numbers
  1. Dim strPK As String
  2.  
  3. strPK = Format(Date(),"mmm")
  4. strPK = strPK & _
  5.         Val(Right(Nz(DMax("[PK]", _
  6.                           "[tblMain]", _
  7.                           "[PK] Like " & strPK & " & '*'"), _
  8.                     "XXX0999"),4))+1
Feb 4 '07 #10

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

Similar topics

8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
0
by: Dennis Ruppert | last post by:
Greetings This should be easy, but I am stuck! I have a table that I import from another program. There are 25 fields, but I only need to use 3 of them for what I need to do. After I import...
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...
6
by: Kd | last post by:
I have the OrderNo set as the following Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") & "-"Format(,"000")+1 This works great until I get to a new month and need the numbers to reset like...
8
praclarush
by: praclarush | last post by:
Ok, I'm new to JavaScript and I'm taking a class for it the assignment in it I'm supposed to create edit a pre-made page to display a marquee that automatically scrolls for the user, as well as give...
1
by: Mike | last post by:
Hi All, I'm using vb.net as my codebehind lang. and the following code is being executed in my aspx.vb page to stamp a DB row. Dim oStatsInfo As New StatsInfo(CartID, Batch, Set, Num, 0, 0, 0,...
7
cori25
by: cori25 | last post by:
I have a query which displays the employee name, month, date, exception. I need to have the query display when an employee has more then 7 consecutive days with a certain exception. Meaning the same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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,...

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.