J
James Griffin
I am using the following VBA code to update time difference entered values -
the code is neraly working however the "TotalTime3" double field has the
correct time in terms of decimal hours but when it assigns it to the form
control "Me.totalhours.Value = TotalTime3" I am getting 13 for
Me.totalhours.Value and 14 for Me.totalhours.Text. I feel there is some
rounding or flooring going on and instead the answer should be 13.5 hours
what do i need to do to ensure this ? I then assign this value to a table.
Should I use code to look either side of the decimal point or is there a
property within the field control ? I have a new book Access 2007 inside and
out and realise the note about decimal points and I have set the field format
property to standard number and read that it should be outputting two decimal
points but instead its just a whole number such as the 13 or 14 and I wish
13.5 or 13.38 for example ......can anyone help please
Private Sub Cmd_sum_total hours()
Dim TotalTime3 As Double
Set DB = CurrentDb
Set rst = DB.OpenRecordset("Clock_Table")
TotalTime3 = ((([ClockoutDay1] - [ClockinDay1])) + (([ClockoutDay2] -
[ClockinDay2])) + (([ClockoutDay3] - [ClockinDay3])) * 24 + (([ClockoutDay4]
- [ClockinDay4]))) * 24
Me.totalhours.DecimalPlaces = 2
Me.totalhours.SetFocus
Me.totalhours.Value = TotalTime3
The answer I am getting
the code is neraly working however the "TotalTime3" double field has the
correct time in terms of decimal hours but when it assigns it to the form
control "Me.totalhours.Value = TotalTime3" I am getting 13 for
Me.totalhours.Value and 14 for Me.totalhours.Text. I feel there is some
rounding or flooring going on and instead the answer should be 13.5 hours
what do i need to do to ensure this ? I then assign this value to a table.
Should I use code to look either side of the decimal point or is there a
property within the field control ? I have a new book Access 2007 inside and
out and realise the note about decimal points and I have set the field format
property to standard number and read that it should be outputting two decimal
points but instead its just a whole number such as the 13 or 14 and I wish
13.5 or 13.38 for example ......can anyone help please
Private Sub Cmd_sum_total hours()
Dim TotalTime3 As Double
Set DB = CurrentDb
Set rst = DB.OpenRecordset("Clock_Table")
TotalTime3 = ((([ClockoutDay1] - [ClockinDay1])) + (([ClockoutDay2] -
[ClockinDay2])) + (([ClockoutDay3] - [ClockinDay3])) * 24 + (([ClockoutDay4]
- [ClockinDay4]))) * 24
Me.totalhours.DecimalPlaces = 2
Me.totalhours.SetFocus
Me.totalhours.Value = TotalTime3
The answer I am getting