Hi,
I am trying to total a column (Shift1) in a subform (continous forms)
from the after update event of the (Shift1) column control within the
subform. This column stores shift codes, I want to sum the hours
associated with these shift codes from the RosterShifts Table.
ie. Shift1 may = D
The D shift is 8 hours long
I am using Dictionary objects within the form as suggested by Gord,
this works well for totalling the hours for a record. I was wondering
if I could use a similar approach for summing the hours for all
records for Shift1.
I have a Public Function called CalcTotalTime2( ) in the afterupdate
event for shift1 please see below - this will be used for all shifts
if it works.
I am getting the error Database can't find the field '|" referred in
your expression.
It seems to be related to my recordset reference as:
Dim frm As Form
Set frm = Me.Form
With frm.RecorsetClo ne
Set rs = Me!RecordsetClo ne
With rs
I have tried a few options does someone know where I am going wrong?
Cheers
Kevin
Private Sub Form_Load() ' Kindly supplied by GORD
Dim cdb As DAO.Database, rst As DAO.Recordset
Dim ShiftRecord As Dictionary
Set ShiftData = New Dictionary
Set cdb = CurrentDb
Set rst = cdb.OpenRecords et("SELECT ShiftID, ShiftDescriptio n,
ShiftPaidTime " & "FROM RosterShifts", dbOpenSnapshot)
Do While Not rst.EOF
Set ShiftRecord = New Dictionary
With ShiftRecord
.Add "ShiftDescripti on", rst!ShiftDescri ption.Value
.Add "ShiftPaidTime" , rst!ShiftPaidTi me.Value
End With
ShiftData.Add rst!ShiftID.Val ue, ShiftRecord
Set ShiftRecord = Nothing
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cdb = Nothing
End Sub
Public Function CalcTotalTime2( )
Dim rs As DAO.Recordset
Dim lngTotal As Long, i As Integer, strCtlName As String, strShiftID
As String
Dim dayTotal As Long
lngTotal = 0
For i = 1 To 28
strCtlName = "Shift" & Format(i, "00")
If Not IsNull(Me.Contr ols(strCtlName) .Value) Then
strShiftID = Me.Controls(str CtlName).Value
lngTotal = lngTotal + ShiftData(strSh iftID)("ShiftPa idTime")
End If
Next
Me.TotalTime.Va lue = lngTotal
lngTotal = 0
Dim strControlName As String, strContValue As String
Dim CrntCtl As Control
Set CrntCtl = Screen.ActiveCo ntrol
strControlName = CrntCtl.Name
Dim frm As Form
Set frm = Me.Form
With frm.RecorsetClo ne
'Set rs = Me!RecordsetClo ne
'With rs
Do Until .EOF
DoCmd.GoToRecor d acActiveDataObj ect, , acFirst
lngTotal = lngTotal + ShiftData(strCo ntrolName)("Shi ftPaidTime")
DoCmd.GoToRecor d acActiveDataObj ect, , acNext
lngTotal = lngTotal + ShiftData(strSh iftID)("ShiftPa idTime")
Loop
SumShift1 = lngTotal
End With
End Function
I am trying to total a column (Shift1) in a subform (continous forms)
from the after update event of the (Shift1) column control within the
subform. This column stores shift codes, I want to sum the hours
associated with these shift codes from the RosterShifts Table.
ie. Shift1 may = D
The D shift is 8 hours long
I am using Dictionary objects within the form as suggested by Gord,
this works well for totalling the hours for a record. I was wondering
if I could use a similar approach for summing the hours for all
records for Shift1.
I have a Public Function called CalcTotalTime2( ) in the afterupdate
event for shift1 please see below - this will be used for all shifts
if it works.
I am getting the error Database can't find the field '|" referred in
your expression.
It seems to be related to my recordset reference as:
Dim frm As Form
Set frm = Me.Form
With frm.RecorsetClo ne
Set rs = Me!RecordsetClo ne
With rs
I have tried a few options does someone know where I am going wrong?
Cheers
Kevin
Private Sub Form_Load() ' Kindly supplied by GORD
Dim cdb As DAO.Database, rst As DAO.Recordset
Dim ShiftRecord As Dictionary
Set ShiftData = New Dictionary
Set cdb = CurrentDb
Set rst = cdb.OpenRecords et("SELECT ShiftID, ShiftDescriptio n,
ShiftPaidTime " & "FROM RosterShifts", dbOpenSnapshot)
Do While Not rst.EOF
Set ShiftRecord = New Dictionary
With ShiftRecord
.Add "ShiftDescripti on", rst!ShiftDescri ption.Value
.Add "ShiftPaidTime" , rst!ShiftPaidTi me.Value
End With
ShiftData.Add rst!ShiftID.Val ue, ShiftRecord
Set ShiftRecord = Nothing
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cdb = Nothing
End Sub
Public Function CalcTotalTime2( )
Dim rs As DAO.Recordset
Dim lngTotal As Long, i As Integer, strCtlName As String, strShiftID
As String
Dim dayTotal As Long
lngTotal = 0
For i = 1 To 28
strCtlName = "Shift" & Format(i, "00")
If Not IsNull(Me.Contr ols(strCtlName) .Value) Then
strShiftID = Me.Controls(str CtlName).Value
lngTotal = lngTotal + ShiftData(strSh iftID)("ShiftPa idTime")
End If
Next
Me.TotalTime.Va lue = lngTotal
lngTotal = 0
Dim strControlName As String, strContValue As String
Dim CrntCtl As Control
Set CrntCtl = Screen.ActiveCo ntrol
strControlName = CrntCtl.Name
Dim frm As Form
Set frm = Me.Form
With frm.RecorsetClo ne
'Set rs = Me!RecordsetClo ne
'With rs
Do Until .EOF
DoCmd.GoToRecor d acActiveDataObj ect, , acFirst
lngTotal = lngTotal + ShiftData(strCo ntrolName)("Shi ftPaidTime")
DoCmd.GoToRecor d acActiveDataObj ect, , acNext
lngTotal = lngTotal + ShiftData(strSh iftID)("ShiftPa idTime")
Loop
SumShift1 = lngTotal
End With
End Function
Comment