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

Data entry of one field calculates value of other field and vice-versa 1

Status
Not open for further replies.

jpkeller55

Technical User
Apr 11, 2003
131
US
Not sure if this is possible. I have a simple database that is tracking number of miles a person walks each day. I would like the user to be able to enter either the distance in miles or the number of strides (from a pedometer)they have walked each day. The part I would like the form to do is calculate the number of strides(StrideNum) if they enter the miles(DistanceWalked) or calculate the distance in miles if they enter the strides.

Here is the query I am using for the form:
Code:
SELECT WalkData.WalkID, WalkData.EmplID, WalkData.Date, WalkData.DistanceWalked, Employees.StrideLth, [DistanceWalked]*63360/[StrideLth] AS StrideNum
FROM WalkData INNER JOIN Employees ON WalkData.EmplID = Employees.EmplID;
The way my query works now, the user can only enter DistanceWalked and the strides are calculated. Thanks for any help you can lend. Jim
 
I would put a "onlostfocus" event on both fields to check the status of the other. If you enter the miles onlostfocus
if isnull(me.stridenum) then
me.stridenum = me.distancewalked * 63360/[StrideLth]
endif
And on the stridenum field put the opposite to update distancewalked.
 
One question...It works if there is not data in either field. But, if after you enter the data in one of the fields and it autopopulates the other field, the user can go in and change either of the fields and it does not update the other field. Do you follow?
 
That's the if/then statement - I assumed (my fault) that if a user entered data in 1 field you would want the other field overwritten only if there wasn't already a value there.

Just take out the if...then & end if lines.
So, distancewalked onlostfocus would simply read:
me.stridenum = me.distancewalked * 63360/[StrideLth]
and vice/versa for the stridenum onlostfocus event.

 
Beautiful...that makes it perfect. dweis, Thanks so much for your help! Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top