A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Field calculation based on data in separate fields within the same subform...



 
 
Thread Tools Display Modes
  #11  
Old January 15th, 2005, 05:36 AM
Steve Schapel
external usenet poster
 
Posts: n/a
Default


Steve Schapel wrote:

... the most likely cause of the problem is a spelling error.
Or, the unlikely event that the name of the textbox in question is the
same as the name of a field in the subform's record source.


.... or that you're using a version of Access prior to Access 2000, in
which case the Round() function will not be recognised.

--
Steve Schapel, Microsoft Access MVP
  #12  
Old January 15th, 2005, 05:39 AM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Rob,

This would indicate that the lunch textbox is not bound to a field in
the form's underlying table/query. Do you have a lunch field in the
table? If so, make sure that the Control Source property of the textbox
on the form is set to point to the lunch field.

--
Steve Schapel, Microsoft Access MVP


rob mccoy via AccessMonster.com wrote:
Steve, another thing that is happening is that when I enter data into
the [in time] [out time] fields -those values only appear in the form
representing that particular day, but when I enter data in to the
[lunch] field-that value carries over into all of the other
forms/records in the subform...

...rob

  #13  
Old January 15th, 2005, 06:58 AM
rob mccoy via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Steve,
OK - The problem with the [lunch] field displaying in all records was an easy fix,but I still can't get the payroll subform to work. This is what I'm working with: Main form contains a subform called [payroll]; which contains a nested subform called [pay period details]; which contains the following fields:[in time], [out time], [lunch], and [Date](this last field doesn't use date() or anything, just manual data entry). Also in the Details area of [pay period details] is an unbound text box called[total daily time]- it uses the expression that you suggested to calculate daily time as it's control source. -oh- i have the unbound text box called [total weekly time] in the footer section of the subform itself ([payroll])- it uses the expression that you suggested to calculate weekly time as it's control source. I'm using Access 2002, here are the problems i'm still having:
1. when i enter a .8(this is the most common lunch length) in the [lunch] field - the field automatically turns the .8 into a 1.
2. the [total daily time] text box returns #name? no matter what data is in the fields that it calculates. i checked everything for spelling errors and couldn't find any.
3. the [total weekly time ] text box returns #error?
I think I might just delete this payroll form(and table) completely and build it from scratch. when i initially created it I added and removed elements as afterthought. Maybe my relationships are screwed up?

--
Message posted via http://www.accessmonster.com
  #14  
Old January 15th, 2005, 07:16 AM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Rob,

rob mccoy via AccessMonster.com wrote:

1. when i enter a .8(this is the most common lunch length) in the [lunch] field - the field automatically turns the .8 into a 1.


Go the the design view of the table, select the lunch field, and look at
the Field Size property. I guess it is set to Integer or Long Integer.
In fact, the best approach in this case is to set the Data Type to
Currency and the Format property to General Number.

2. the [total daily time] text box returns #name? no matter what data is in the fields that it calculates. i checked everything for spelling errors and couldn't find any.


We'll crack it eventually! Just as an experiment, try it without the
Round() function, i.e.
=([out time]-[in time])*24-[lunch]
If that doesn't give a "real" answer, try it simply as...
=[out time]-[in time]
Let me know.

3. the [total weekly time ] text box returns #error?


This will need to be in the Footer of [pay period details], not [payroll].

I think I might just delete this payroll form(and table) completely and build it from scratch. when i initially created it I added and removed elements as afterthought. Maybe my relationships are screwed up?


Well, I still don't know what the problem is, but Relationships are not
relevant.


--
Steve Schapel, Microsoft Access MVP
  #15  
Old January 15th, 2005, 10:05 AM
rob mccoy via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Steve,
I tried something- instead of manually entering the expression- i used the expression builder to "build" the expression you suggested:=Round(([out time]-[in time])*24-[lunch],1) for calculating daily time - it worked- well kind of worked - it will do a calculation, but if a 2nd shift person works past midnight , or more than 12 hours - it returns negative values, or wrong values. for instance: if i input an [in time] of 6pm and an [out time] of 12am with a .8 [lunch] - it returns a value of 17.2, or 7pm- 9pm returns -2.
I used the expression builder to duplicate the expression for calculation total weekly hours too:=Round(Sum(([End Time]-[Start Time])*24-[Lunch]),1) it returns the proper numerical values except that they are negative...

suggestions?

thanks,

rob

--
Message posted via http://www.accessmonster.com
  #16  
Old January 15th, 2005, 06:04 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Rob,

Are the actual names of the fields [End Time] and [Start Time] rather
than [out time] and [in time]? This would certainly explain the
previous error!

Regarding the negative value, could it be possible that you have the
controls accidentally reversed on the form, so that the worker's start
time is being entered into the [End Time] field and vice versa?

To handle the fact that the work "day" may span across midnight,
probably the simplest approach is to have the [End Time] and [Start
Time] fields to include a date component as well as a time component, or
else to have additional fields for [End Date] and [Start Date]. Is this
feasible? Otherwise, it is a bit complicated, but it would be possible
to put together a "user-defined function" to work this out for you.

--
Steve Schapel, Microsoft Access MVP

rob mccoy via AccessMonster.com wrote:
Steve, I tried something- instead of manually entering the
expression- i used the expression builder to "build" the expression
you suggested:=Round(([out time]-[in time])*24-[lunch],1) for
calculating daily time - it worked- well kind of worked - it will do
a calculation, but if a 2nd shift person works past midnight , or
more than 12 hours - it returns negative values, or wrong values. for
instance: if i input an [in time] of 6pm and an [out time] of 12am
with a .8 [lunch] - it returns a value of 17.2, or 7pm- 9pm returns
-2. I used the expression builder to duplicate the expression for
calculation total weekly hours too:=Round(Sum(([End Time]-[Start
Time])*24-[Lunch]),1) it returns the proper numerical values except
that they are negative...

suggestions?

thanks,

rob

  #17  
Old January 15th, 2005, 09:43 PM
rob mccoy via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Steve,

The field names were [in time] [out time] , and thatwas how they were represented in the expression , but when you suggested a spelling error - i went back thrugh all the forms, subforms, and underlying tables and in the process of doing so changed those field names.

About the field controls for [start time] [end time]- I'm not sure what you mean - I'm just manually entering the data into these fields. Is there a way to add a date tag to these fields?

Anyway Steve-I really appreciate all of the help. Thanks again...\

....rob

--
Message posted via http://www.accessmonster.com
  #18  
Old January 15th, 2005, 09:52 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Rob,

A Date/Time field can have a date entered, a time entered, or a date and
time entered. At the moment you are only entering the time, but with no
change at all to your system (except possibly making the textbox on the
form wider!), you can enter like this...
1/16/05 9:00
.... and that way your calculations will take account of the midnight
factor, because the [End Time] will be the following date.

--
Steve Schapel, Microsoft Access MVP


rob mccoy via AccessMonster.com wrote:
Steve,

The field names were [in time] [out time] , and thatwas how they were
represented in the expression , but when you suggested a spelling
error - i went back thrugh all the forms, subforms, and underlying
tables and in the process of doing so changed those field names.

About the field controls for [start time] [end time]- I'm not sure
what you mean - I'm just manually entering the data into these
fields. Is there a way to add a date tag to these fields?

Anyway Steve-I really appreciate all of the help. Thanks again...\

...rob

  #19  
Old January 16th, 2005, 06:20 PM
rob mccoy via AccessMonster.com
external usenet poster
 
Posts: n/a
Default

Steve,
Hey - thanks for that last tip. it works great.

how do you write an expression that gives the intruction to Sum a field if the data entered into another field is a particular text value.
this is what i tried: =sum(IIf[field name]="text"),0,[field being summed]))

It doesn't work.

thanks again...


....rob

--
Message posted via http://www.accessmonster.com
  #20  
Old January 16th, 2005, 06:34 PM
Steve Schapel
external usenet poster
 
Posts: n/a
Default

Rob,

Looks like the general idea is right, but parentheses slightly
misplaced. Try it like this...
=Sum(IIf([field name]="text",0,[field being summed]))

--
Steve Schapel, Microsoft Access MVP

rob mccoy via AccessMonster.com wrote:
Steve,
Hey - thanks for that last tip. it works great.

how do you write an expression that gives the intruction to Sum a field if the data entered into another field is a particular text value.
this is what i tried: =sum(IIf[field name]="text"),0,[field being summed]))

It doesn't work.

thanks again...


...rob

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Additional fields for form based parameter query/null fields geeksdoitbetter Running & Setting Up Queries 2 January 7th, 2005 10:05 PM
New Record Update Michelle Using Forms 5 October 28th, 2004 07:59 AM
SQL view of messed up action queries Kendra Running & Setting Up Queries 2 August 31st, 2004 09:53 PM
Filtering records in a form based on data in a subform or query. jbuck Using Forms 0 August 5th, 2004 02:51 PM
Inputting data from one source to many fields Maskedman Database Design 1 June 18th, 2004 06:24 PM


All times are GMT +1. The time now is 03:48 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.