Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counter on a Continuous Form

Status
Not open for further replies.

kb178

IS-IT--Management
Aug 16, 2001
83
0
0
US
I have a continous form where I have two fields for people to enter the beginning and end dates of the week of their vacation. All I want to be able to do is have a label for Week 1, and then when the next form comes up it would say Week 2. I found this code in another thread:

Public Function NextI()
Static i As Integer
i = i + 1
NextI = i
End Function

When the form opens, the first record says "Week 1." As soon as I start typing, it changes to Week 2. Then the next one will say Week 3, but when I start typing there it changes to Week 4. So my form winds having Week 2 and Week 4, instead of Week 1, and Week 2.

Why is it adding 2? Thanks!
 
Seems to me that you might be executing the function twice. Possible in the NewRecord event and the GotFocus event. (Not sure what their exact names are) Check and ensure that you are only making the function call once per new record.
 
Thanks for the reply. I checked everywhere on the form and that code is only in there once. There's no other event properties pointing to that code. If I go to View->Code, all I see is my public function of NextI().
 
Need more input.

What event is the one calling the nexti function? and is it a controls event, forms event, ect.?

The function is working. It's only adding 1 to each week such as week1 changes to week2, and then goes to week3 which changes to week4. The function is being applied twice for each week. If the event is an On Update, then Access might be consider opening the record an update and editing the record an update, therefore redundantly calling it.
 
It's not on anything. I just have the form open, and go to View->Code and put the code in there. I have a text box where the control is =NextI()
Hope that helps!
 
Move the function call from the control source to the default value, then set the textbox's Locked feature to yes so they can't change it.
 
Genius! Thanks so much for your help, it works now! :)
 
I spoke to soon. Put it in as the default, but if you close out of the form and go back the newest record becomes 1 again. Any suggestions?
 
I don't think I'm following you on what you want accomplished.
So let's say a user inputs the dates and week 1 and week 2 show up as they should. Then if they close it and come back to enter another vaction time it should be week 3 and week 4? and also are you storing week 1,2,ect in a table?
It seems to me, that we could manipulate the incremental counter to work, but it's poor programming to do so. I need a better understanding of what these values will be used for and if/where they stored.
 
Basically I have a table with the id of the person (all their info is in another table) with a beginning date and an ending date. The incremental number I'm looking for is really only for visual purposes. The form I'm trying to put this incremental number on is actually a subform. I have the employee information as the parent form, and the subform has the continuous form setting.

By setting NextI() as the default, I get 1 and 2 when I first open the form. Those numbers are stored as such. Then when the form is opened for the same person, it'll have the correct numbers stored for the previously done records, but new records come up again as 1, 2, and so on.

So, here is what I'm getting:

With NextI() as the control I get:
Week 2
Week 4
Week 6...

With NextI() as the default and being stored (this would be after entering one record and reopening the form):
Week 1
Week 2
Week 1
Week 2
 
You really shouldn't be using an incremental counter for this. You should read the field form the table and increment it by one for the first formw's box, then set the control source on the second forms box equal to the first form's box plus one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top