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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Loop through data base to update recordset

Status
Not open for further replies.

Rainer2000

IS-IT--Management
Apr 27, 2003
61
0
0
DE
I have written the following code in a Form:
Private Sub Befehl90_Click()
If Me.Text86 < #12/31/1988# Then Text69 = "ERW"
If Me.Text86 >= #1/1/1989# And Me.Text86 < #12/31/1990# Then Text69 = "U19"
If Me.Text86 >= #1/1/1991# And Me.Text86 < #12/31/1992# Then Text69 = "U17"
If Me.Text86 >= #1/1/1993# And Me.Text86 < #12/31/1994# Then Text69 = "U15"
If Me.Text86 >= #1/1/1995# And Me.Text86 < #12/31/1996# Then Text69 = "U13"
If Me.Text86 >= #1/1/1997# And Me.Text86 Then Text69 = "U11"
End Sub
This Code calculates in which age category the members of my team comes.
This works fine: I am using a Doubleclick Code to calculate.
I have been trying to automatize this Code so it will walk through the whole database and calculeate for each recordset when clicking on the calculate button on the Form.
Something like : Do While Not EOF, but I could not make it work.
Any help available?

Rainer




 
presumably you've got a form bound to a table or query to do this, and you want to automatically step through the records on the form, and calculate the data for each record that way...

would it not be better to use an update query to update all the records in one go? Something like:

update tableName
set columnName = GetAgeGroup(dateField)

the GetAgeGroup would be a custom function in one of your modules where you would pass in a date, and the function would return the age group value.

--------------------
Procrastinate Now!
 
Rainer, what is the category of someone born a december, 12 since 1987 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Rainer,

Looking at your code, I am guessing that your age groups are something like "Under 11", "Under 13", "Under 15", etc. If that is the case, you may benefit from looking at a different way of doing this.

You may want to search here for some of the FAQs or posts that talk about calculating someone's age, then comparing this against a simple check of how old they are. I also might recommend you do this through a query or some such and NOT store this in the tables unless you think this is really the best method.

Reasoning behind these suggestions is that at the beginning of each year you will have to remember to come in and update the function and then update all the records as well or the "age groups" will be off. Working with an age calculation function, and then if necessary applying some other functioning values to make them fit your "time frame" differential, will provide a much more robust and accurate application.

Let us know if you have any questions related to my suggestions and anyone else add their comments as well.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
OOps, sorry for the typo:
born a december, 31
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top