Hi Sam, Duane and Rick,
Well I have managed to get the data out and formait it correctly. What the
code is not doing is adding the correct data. I have set a where clause
that should filter the values to be added by the bill number. When I run
the query on its own it returns the correct total. But in the event it adds
up every value in the Durations field. I don't understand it. If it goes
in to debug mode I can rest the cursor over the variables and they all come
out correct, except for Tot = rst!Sum. Bill = the correct bill number which
is passed in to the query, so why is it not filtering correctly? Please see
code below:
-----------------------------------------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
'Total of filtered Durations
Dim Tot As Double
'The number of the current bill stored in a hidden textbox, txtBillHdn
Dim Bill As String
Bill = Form_frmMobile_Bills.txtBillHdn
Set db = CurrentDb
'Recordset filtered by Bill
Set rst = db.OpenRecordset("SELECT Sum([UK>Int_Calls].Durations) AS [Sum]
FROM [UK>Int_Calls] WHERE ((([UK>Int_Calls].Bill)= '" & Bill & "'));")
'Total equals sum of all values in Durations field, not filtered. This is a
problem!
Tot = rst!Sum
DayDur = Int(Tot): HrDur = Hour(Tot): MinDur = Minute(Tot): SecDur =
Second(Tot)
Me.txtIntCAllUKDur = CStr((DayDur * 24) + HrDur) + ":" + CStr(MinDur) + ":"
+ CStr(SecDur)
-----------------------------------------------------------------------------
The other thing that I am thinking about is how do I make it possible to do
the reverse. I suppose it can't be that hard; I suppose use Cast or
something like that to concatenate the parts of the string that will be
used:
e.g. 3600 times the hours value, 60 * the minutes value, 1 * the seconds
value, and then add all three.
Am I on the right track? When do you think a datatype will be created that
stores time as an amount of time so that you don't have to do all this?
Honestly, it's an absolute nonsense.
The third thing I am having trouble with is getting the correct value out of
a recordset. I have want to add a value to a field (CallCost), and on
AfterUpdate it must tally up all the values in it field (filtered by Bill,
again). But the value it uses is the sum less the new value. It is as if
it hasn't been committed to the database by the time the recordset is
populated. So it is always one step behind. All I can think is to use an
update query to insert the value before loading the recordset to force the
value in there from the first. Is there a better way?
TIA,
Jarryd
Jarryd said:
That is some clever stuff. I haven't tried it yet. I have to get some
shut eye soon or I might as well just stay awake. But it all makes sense
but if you could please check bakc on this thread I would appreciate it.
TIA,
Jarryd
OfficeDev18 via AccessMonster.com said:
Rick said:
Hi Duane and Rick,
[quoted text clipped - 21 lines]
in what I assume, because it seems like quite a lot of work to
achieve something very simple. I hope I am wrong.
That is pretty much what you want to do. In some case you can have the
user enter start and end times and then use DateDiff() to get the seconds
difference with one simple expression.
How do you plan on tracking calls that originate at 11:59 pm and end at
12:01
am or later?
Suggestion: I've done this after much sweat and tears: store the begin
and
end times as Doubles. At 4 pm today, that would be 38617.66666. If the
call
lasts past midnight, the number left of the decimal (the 'days' portion)
will
be 38618, and the number to the right (the hours, minutes, and seconds
portion) will be whatever. To get the actual duration, subtract the two
numbers and multiply by 24 [Duration = 24*(EndTime - BeginTime)]. If you
want
to display it in hh:mm:ss format, it won't work if beyond 24 hours, as
you
already know. You'll probably get away with 27.032 hours faster than
getting
away with "hiding" 24 hours of phone usage. Besides, you could always
sweat
through the code of building a string with the exact format, as long as
you
don't use the format() function.
Example: say your addition of all durations comes out to 1.03439 (before
multiplication); cal it Tot. You can type
DayDur=Int(Tot): HrDur = Hour(Tot): MinDur = Minute(Tot): SecDur =
Second(Tot)
txtTotDur = CStr((DayDur * 24) + HrDur) + ":" + CStr(MinDur) + ":" + CStr
(SecDur)
This should display 24:49:31
--
Sam
Message posted via AccessMonster.com