473,394 Members | 1,663 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,394 software developers and data experts.

Help with counter condition!

Hey All...

I have a form that has a Before Update event of:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then

Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End If
End Sub
Basically every new record the displayedRunNumber is incremented by 1
and stored. I know some people question why its a Before Update but
thats the way it needs to be.

Heres the problem. I need the number to reset counting to 0001
automatically each new year. For example... the first entry this year
is 0001 and it will keep going up with each new record 0002.... and so
on. When it hits 2007, I need somehow for the first entry of 2007 to
start back at 0001 again and continue counting up.

Help would be greatly appreciated.. I'm kind of new to access so if you
cite code please let me know where it is supposed to go and how it
should look.

Thanks in advance,

BG

Aug 15 '06 #1
2 1384
so use DCount and Year(Date) as part of your formula, so you the code
resets the counter every year.

Aug 15 '06 #2
br***********@gmail.com wrote in
news:11**********************@75g2000cwc.googlegro ups.com:
Hey All...

I have a form that has a Before Update event of:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then

Me!displayedRunNumber =
Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End If
End Sub
Basically every new record the displayedRunNumber is
incremented by 1 and stored. I know some people question why
its a Before Update but thats the way it needs to be.

Heres the problem. I need the number to reset counting to 0001
automatically each new year. For example... the first entry
this year is 0001 and it will keep going up with each new
record 0002.... and so on. When it hits 2007, I need somehow
for the first entry of 2007 to start back at 0001 again and
continue counting up.

Help would be greatly appreciated.. I'm kind of new to access
so if you cite code please let me know where it is supposed to
go and how it should look.

Thanks in advance,

BG
In your code, you need to modify
DMax("displayedRunNumber","fields")
to something that filters for the year. For this you will nead a
date field in the table that you can check for the year. and the
year from the computer's clock.

say that field is called RunDate, so your expression becomes.
DMax("displayedRunNumber","fields","year(rundate)= year(now()")

The rest of the code stays exactly the same.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 15 '06 #3

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

Similar topics

16
by: Paul Rubin | last post by:
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. ...
3
by: David | last post by:
Hi, I'd like to adapt the query below to select records only if the Title field contains the string "Book" (as an example). I'd also like to use a different variant of the query elsewhere to...
2
by: wrrn | last post by:
Hi - I'm beginning work on an existing web site which was created with Adobe Golive. The page in question has CSACTIONS which is part of Golive's CyberStudio. Anyway, the code below has this...
6
by: phil goddard | last post by:
This homework tests your understanding of pointers and how to use pointers with arrays and functions. What we want to do is find the next highest int in an array based on a given float, i.e. in...
8
by: phil goddard | last post by:
This homework tests your understanding of pointers and how to use pointers with arrays and functions. What we want to do is find the next highest int in an array based on a given float, i.e. in...
7
by: brian.digipimp | last post by:
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd...
1
by: C-- | last post by:
for (expression1; expression2; expression3) {statement} can you explain it to me...
8
by: bmlclemson08 | last post by:
Hey if anyone could I need to find out how to write a program that will read in any number of integers, including none, and determine which is the largest integer. The part i can't figure out is...
1
by: abatesf | last post by:
I need to write a tax calculation program in C for a store chain. There 4 stores and 4 different tax rates .0700, .0725, .07500 and .0775 This is what i have so far... any suggestions #include...
28
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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...

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.