G
Guest
I am very new to VBA. I have had only a brief introduction in my MS App
college course. I am trying to get a value in an unbound calculated control
to round up or down depending on the value. This is a timesheet database.
The line giving me a problem is:
lngDlyHrsWrked = Forms!subfrmDailyTimeWTotalsWeek1.DailyHoursWorked.Value
"The error is Run-Time Error: 2450
Timesheets - QED Management can't find the form 'subfrmDailyTimeWeek1'
referred to in a macro expression or Visual Basic Code."
I feel like this is a simple syntax problem, but I have not been able to fix
it.
Form Information:
The main form is based on a query that limits the dates to the current pay
period. There are two sub forms on the main form. The first sub form is
limited by a query that shows week 1 in the current pay period. The second
form is limited by a query that shows week 2 in the current pay period. The
main form’s header houses the Employee Name, EmployeeID, Department, Team,
and CostCenter fields (all fields from tblEMpInfo). The DailyHoursWorked
field is calculated by the sub form’s query (additional info below).
I have tried several different things to get the unbound control
(DailyHoursWorked) to display the rounded value. Originally, I did not have
the line above in my code at all. I am not sure what I am doing wrong. I
have the code in an Access module. I have tried the same code as a Public
Sub, but I read that a Sub cannot return a value, so I really didn’t expect
that to work. I am calling this Function from the AfterUpdate Events of the
TimeIn, and Time Out Fields on my form in order for it to recalculate the
DailyHoursWorked field after the employee changes the values in the TimeIn
and TimeOut fields. There are 4 TimeIn and 4 TimeOut fields (TimeIn1,
TimeOut1, Time In2, etc.) that are stored in a table named tblTimeCard. The
form is based on a query, that combines fields from tblTimeCard and
tblEmpInfo. The EmployeeID is the Primary Key in tblEmpInfo. The primary
key in tblTimeCard is EmployeeID and Date. These tables have a one-to-many
relationship based on EmployeeID, with referential integrity enforced. The
one side of the relationship is, of course, the tblEmpInfo. Any help is
greatly appreciated.
My code is as follows:
Public Function RoundDailyHrsWorked()
Dim lngDlyHrsWrked As Long
lngDlyHrsWrked = Forms!subfrmDailyTimeWTotalsWeek1.DailyHoursWorked.Value
Select Case lngDlyHrsWrked
Case Is <= 0.1167
lngDlyHrsWrked = 0#
Case Is <= 0.35
lngDlyHrsWrked = 0.25
Case Is <= 0.6167
lngDlyHrsWrked = 0.5
Case Is <= 0.8667
lngDlyHrsWrked = 0.75
Case Is <= 1.1167
lngDlyHrsWrked = 1#
Case Is <= 1.35
lngDlyHrsWrked = 1.25
Case Is <= 1.6167
lngDlyHrsWrked = 1.5
Case Is <= 1.8667
lngDlyHrsWrked = 1.75
Case Is <= 2.1167
lngDlyHrsWrked = 2#
Case Is <= 2.35
lngDlyHrsWrked = 2.25
Case Is <= 2.6167
lngDlyHrsWrked = 2.5
Case Is <= 2.8667
lngDlyHrsWrked = 2.75
Case Is <= 3.1167
lngDlyHrsWrked = 3#
Case Is <= 3.35
lngDlyHrsWrked = 3.25
Case Is <= 3.6167
lngDlyHrsWrked = 3.5
Case Is <= 3.8667
lngDlyHrsWrked = 3.75
Case Is <= 4.1167
lngDlyHrsWrked = 4#
Case Is <= 4.35
lngDlyHrsWrked = 4.25
Case Is <= 4.6167
lngDlyHrsWrked = 4.5
Case Is <= 4.8667
lngDlyHrsWrked = 4.75
Case Is <= 5.1167
lngDlyHrsWrked = 5#
Case Is <= 5.35
lngDlyHrsWrked = 5.25
Case Is <= 5.6167
lngDlyHrsWrked = 5.5
Case Is <= 5.8667
lngDlyHrsWrked = 5.75
Case Is <= 6.1167
lngDlyHrsWrked = 6#
Case Is <= 6.35
lngDlyHrsWrked = 6.25
Case Is <= 6.6167
lngDlyHrsWrked = 6.5
Case Is <= 6.8667
lngDlyHrsWrked = 6.75
Case Is <= 7.1167
lngDlyHrsWrked = 7#
Case Is <= 7.35
lngDlyHrsWrked = 7.25
Case Is <= 7.6167
lngDlyHrsWrked = 7.5
Case Is <= 7.8667
lngDlyHrsWrked = 7.75
Case Is <= 8.1167
lngDlyHrsWrked = 8#
Case Is <= 8.35
lngDlyHrsWrked = 8.25
Case Is <= 8.6167
lngDlyHrsWrked = 8.5
Case Is <= 8.8667
lngDlyHrsWrked = 8.75
Case Is <= 9.1167
lngDlyHrsWrked = 9#
Case Is <= 9.35
lngDlyHrsWrked = 9.25
Case Is <= 9.6167
lngDlyHrsWrked = 9.5
Case Is <= 9.8667
lngDlyHrsWrked = 9.75
Case Is <= 10.1167
lngDlyHrsWrked = 10#
Case Is <= 10.35
lngDlyHrsWrked = 10.25
Case Is <= 10.6167
lngDlyHrsWrked = 10.5
Case Is <= 10.8667
lngDlyHrsWrked = 10.75
Case Is <= 11.1167
lngDlyHrsWrked = 11#
Case Is <= 11.35
lngDlyHrsWrked = 11.25
Case Is <= 11.6167
lngDlyHrsWrked = 11.5
Case Is <= 11.8667
lngDlyHrsWrked = 4.75
Case Is <= 12.1167
lngDlyHrsWrked = 12#
Case Is <= 12.35
lngDlyHrsWrked = 12.25
Case Is <= 12.6167
lngDlyHrsWrked = 12.5
Case Is <= 12.8667
lngDlyHrsWrked = 12.75
Case Is <= 13.1167
lngDlyHrsWrked = 13#
End Select
End Function
Thanks in advance!
Tiffany
college course. I am trying to get a value in an unbound calculated control
to round up or down depending on the value. This is a timesheet database.
The line giving me a problem is:
lngDlyHrsWrked = Forms!subfrmDailyTimeWTotalsWeek1.DailyHoursWorked.Value
"The error is Run-Time Error: 2450
Timesheets - QED Management can't find the form 'subfrmDailyTimeWeek1'
referred to in a macro expression or Visual Basic Code."
I feel like this is a simple syntax problem, but I have not been able to fix
it.
Form Information:
The main form is based on a query that limits the dates to the current pay
period. There are two sub forms on the main form. The first sub form is
limited by a query that shows week 1 in the current pay period. The second
form is limited by a query that shows week 2 in the current pay period. The
main form’s header houses the Employee Name, EmployeeID, Department, Team,
and CostCenter fields (all fields from tblEMpInfo). The DailyHoursWorked
field is calculated by the sub form’s query (additional info below).
I have tried several different things to get the unbound control
(DailyHoursWorked) to display the rounded value. Originally, I did not have
the line above in my code at all. I am not sure what I am doing wrong. I
have the code in an Access module. I have tried the same code as a Public
Sub, but I read that a Sub cannot return a value, so I really didn’t expect
that to work. I am calling this Function from the AfterUpdate Events of the
TimeIn, and Time Out Fields on my form in order for it to recalculate the
DailyHoursWorked field after the employee changes the values in the TimeIn
and TimeOut fields. There are 4 TimeIn and 4 TimeOut fields (TimeIn1,
TimeOut1, Time In2, etc.) that are stored in a table named tblTimeCard. The
form is based on a query, that combines fields from tblTimeCard and
tblEmpInfo. The EmployeeID is the Primary Key in tblEmpInfo. The primary
key in tblTimeCard is EmployeeID and Date. These tables have a one-to-many
relationship based on EmployeeID, with referential integrity enforced. The
one side of the relationship is, of course, the tblEmpInfo. Any help is
greatly appreciated.
My code is as follows:
Public Function RoundDailyHrsWorked()
Dim lngDlyHrsWrked As Long
lngDlyHrsWrked = Forms!subfrmDailyTimeWTotalsWeek1.DailyHoursWorked.Value
Select Case lngDlyHrsWrked
Case Is <= 0.1167
lngDlyHrsWrked = 0#
Case Is <= 0.35
lngDlyHrsWrked = 0.25
Case Is <= 0.6167
lngDlyHrsWrked = 0.5
Case Is <= 0.8667
lngDlyHrsWrked = 0.75
Case Is <= 1.1167
lngDlyHrsWrked = 1#
Case Is <= 1.35
lngDlyHrsWrked = 1.25
Case Is <= 1.6167
lngDlyHrsWrked = 1.5
Case Is <= 1.8667
lngDlyHrsWrked = 1.75
Case Is <= 2.1167
lngDlyHrsWrked = 2#
Case Is <= 2.35
lngDlyHrsWrked = 2.25
Case Is <= 2.6167
lngDlyHrsWrked = 2.5
Case Is <= 2.8667
lngDlyHrsWrked = 2.75
Case Is <= 3.1167
lngDlyHrsWrked = 3#
Case Is <= 3.35
lngDlyHrsWrked = 3.25
Case Is <= 3.6167
lngDlyHrsWrked = 3.5
Case Is <= 3.8667
lngDlyHrsWrked = 3.75
Case Is <= 4.1167
lngDlyHrsWrked = 4#
Case Is <= 4.35
lngDlyHrsWrked = 4.25
Case Is <= 4.6167
lngDlyHrsWrked = 4.5
Case Is <= 4.8667
lngDlyHrsWrked = 4.75
Case Is <= 5.1167
lngDlyHrsWrked = 5#
Case Is <= 5.35
lngDlyHrsWrked = 5.25
Case Is <= 5.6167
lngDlyHrsWrked = 5.5
Case Is <= 5.8667
lngDlyHrsWrked = 5.75
Case Is <= 6.1167
lngDlyHrsWrked = 6#
Case Is <= 6.35
lngDlyHrsWrked = 6.25
Case Is <= 6.6167
lngDlyHrsWrked = 6.5
Case Is <= 6.8667
lngDlyHrsWrked = 6.75
Case Is <= 7.1167
lngDlyHrsWrked = 7#
Case Is <= 7.35
lngDlyHrsWrked = 7.25
Case Is <= 7.6167
lngDlyHrsWrked = 7.5
Case Is <= 7.8667
lngDlyHrsWrked = 7.75
Case Is <= 8.1167
lngDlyHrsWrked = 8#
Case Is <= 8.35
lngDlyHrsWrked = 8.25
Case Is <= 8.6167
lngDlyHrsWrked = 8.5
Case Is <= 8.8667
lngDlyHrsWrked = 8.75
Case Is <= 9.1167
lngDlyHrsWrked = 9#
Case Is <= 9.35
lngDlyHrsWrked = 9.25
Case Is <= 9.6167
lngDlyHrsWrked = 9.5
Case Is <= 9.8667
lngDlyHrsWrked = 9.75
Case Is <= 10.1167
lngDlyHrsWrked = 10#
Case Is <= 10.35
lngDlyHrsWrked = 10.25
Case Is <= 10.6167
lngDlyHrsWrked = 10.5
Case Is <= 10.8667
lngDlyHrsWrked = 10.75
Case Is <= 11.1167
lngDlyHrsWrked = 11#
Case Is <= 11.35
lngDlyHrsWrked = 11.25
Case Is <= 11.6167
lngDlyHrsWrked = 11.5
Case Is <= 11.8667
lngDlyHrsWrked = 4.75
Case Is <= 12.1167
lngDlyHrsWrked = 12#
Case Is <= 12.35
lngDlyHrsWrked = 12.25
Case Is <= 12.6167
lngDlyHrsWrked = 12.5
Case Is <= 12.8667
lngDlyHrsWrked = 12.75
Case Is <= 13.1167
lngDlyHrsWrked = 13#
End Select
End Function
Thanks in advance!
Tiffany