473,416 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Complicated continous form column Sum

Kev
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.RecorsetClone
Set rs = Me!RecordsetClone
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.OpenRecordset("SELECT ShiftID, ShiftDescription,
ShiftPaidTime " & "FROM RosterShifts", dbOpenSnapshot)
Do While Not rst.EOF
Set ShiftRecord = New Dictionary
With ShiftRecord
.Add "ShiftDescription", rst!ShiftDescription.Value
.Add "ShiftPaidTime", rst!ShiftPaidTime.Value
End With
ShiftData.Add rst!ShiftID.Value, 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.Controls(strCtlName).Value) Then
strShiftID = Me.Controls(strCtlName).Value
lngTotal = lngTotal + ShiftData(strShiftID)("ShiftPaidTime")
End If
Next
Me.TotalTime.Value = lngTotal
lngTotal = 0

Dim strControlName As String, strContValue As String
Dim CrntCtl As Control
Set CrntCtl = Screen.ActiveControl
strControlName = CrntCtl.Name

Dim frm As Form
Set frm = Me.Form

With frm.RecorsetClone
'Set rs = Me!RecordsetClone
'With rs
Do Until .EOF
DoCmd.GoToRecord acActiveDataObject, , acFirst
lngTotal = lngTotal + ShiftData(strControlName)("ShiftPaidTime")
DoCmd.GoToRecord acActiveDataObject, , acNext
lngTotal = lngTotal + ShiftData(strShiftID)("ShiftPaidTime")
Loop
SumShift1 = lngTotal

End With
End Function

Apr 5 '07 #1
1 2807
Hi Kev,

To answer your question:
=================
I think your problem is with the way you have set up your RecordsetClone.
Me.RecordsetClone returns a recodset based on the main form, not the
subform.
Me![subform name here].Form.RecordsetClone should do the trick as far as
that goes.

I'm an Access 97 user, so I don't know anything about "Dictionaries" ...
I'm a little confused by the fact that you seem to be mixing form object
references in with your recordset.
It also appears that you have 28 (unbound text-boxes?) named "Shift01" to
"Shift28" ... what's the purpose there?

Anyway:
ALTERNATE SOLUTION :
====================
Couldn't this be done by simply using a DSum() of ShiftPaidTime?

I'd suggest creating two unbound controls on the main form:

1.) An unbound combo-box (cboShiftID) to choose a ShiftID value (i.e A, B,
C, D...) from
Use this as the Row Source property :
SELECT DISTINCT RosterShifts.ShiftID FROM RosterShifts
ORDER BY RosterShifts.ShiftID;

2.) An unbound textbox (txtSumShiftTime) with this as it's Control Source:
=DSum("ShiftPaidTime","RosterShifts","([ShiftID] = '" & Me![cboShiftID] &
"')")

If "txtShiftTime" doesn't automatically recalculate it's value after
entering a value in the subform control, you may have to trigger a "Refresh"
(or "Repaint"?) of the main form in your AfterUpdate() event.

==========================
--
HTH,
Don
=============================
E-Mail (if you must) My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code samples are also Access97- based
unless otherwise noted.

================================================== ========================
"Kev" <ke***********@nhw.hume.org.auwrote in message
news:11**********************@w1g2000hsg.googlegro ups.com...
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.RecorsetClone
Set rs = Me!RecordsetClone
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.OpenRecordset("SELECT ShiftID, ShiftDescription,
ShiftPaidTime " & "FROM RosterShifts", dbOpenSnapshot)
Do While Not rst.EOF
Set ShiftRecord = New Dictionary
With ShiftRecord
.Add "ShiftDescription", rst!ShiftDescription.Value
.Add "ShiftPaidTime", rst!ShiftPaidTime.Value
End With
ShiftData.Add rst!ShiftID.Value, 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.Controls(strCtlName).Value) Then
strShiftID = Me.Controls(strCtlName).Value
lngTotal = lngTotal + ShiftData(strShiftID)("ShiftPaidTime")
End If
Next
Me.TotalTime.Value = lngTotal
lngTotal = 0

Dim strControlName As String, strContValue As String
Dim CrntCtl As Control
Set CrntCtl = Screen.ActiveControl
strControlName = CrntCtl.Name

Dim frm As Form
Set frm = Me.Form

With frm.RecorsetClone
'Set rs = Me!RecordsetClone
'With rs
Do Until .EOF
DoCmd.GoToRecord acActiveDataObject, , acFirst
lngTotal = lngTotal + ShiftData(strControlName)("ShiftPaidTime")
DoCmd.GoToRecord acActiveDataObject, , acNext
lngTotal = lngTotal + ShiftData(strShiftID)("ShiftPaidTime")
Loop
SumShift1 = lngTotal

End With
End Function

Apr 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JK | last post by:
Hi All, I am working a form which is tabular layout (continuous form) which will display multiple records at a time. Each line of record needs to be reflected on the color code to show their...
1
by: adolph | last post by:
I would like to add a check box to the detail area of a continous form. So that I can check on specific records, then after I've marked all the records I watn to delte, click a button to loop thru...
9
by: Paradigm | last post by:
I am using an Access2K front end to a MYSQL database. If I enter a new record in a continuous form the record appears as #deleted as soon as I move to a different record in the form until I requery...
1
by: SorboPos | last post by:
Hi. I have a form with continuous forms and a data entry section in the header of the form. (I.e. all transactions show in the main form area like a data sheet and the data for the highlighed...
0
by: gavo | last post by:
Hi. using A2K; i have a form containing a continous subform. The question is, how can i call a calculation for one of the fields in the continous subform from the main form. At the moment i...
0
by: ReidarT | last post by:
I have started to develop in vb.net. Earlier development was in MS-Access. I need a lot of continous forms to present data. The customer add and edits data in the continous form. Is use of...
5
by: Nothing | last post by:
I have a search results form that is being displayed as a continous form. I want to double click the name and then using VBA select the different columns of information. For Example: Name ...
2
by: questionit | last post by:
Hi I know how to implement Continous form. In the method i have tried, the source for data on the continous form comes from table using SQL query Now, i want to try something different and i...
5
by: AccessHunter | last post by:
Hi, I have a continous form that displays Name and Address of Suppliers. In the form there is a combo box for 'Active Address' and 10 other text boxes. All the fields coem from one table,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.