Sum in unbound text box returns #error (1 Viewer)

aymarhoon

Registered User.
Local time
Yesterday, 18:55
Joined
Sep 18, 2018
Messages
10
Hi everybody

Is there a way to sum unbound box. I read several threads and tried their suggested solutions but none of them worked. I attach the database to give you an idea about the problem.

Any idea would be greatly appreciated.

Thanks
 

Attachments

  • Database.accdb
    768 KB · Views: 73

June7

AWF VIP
Local time
Yesterday, 17:55
Joined
Mar 9, 2014
Messages
5,488
Aggregate function must reference a field, not a control. Otherwise, have to repeat all the calculations within the Sum() function. And those calculations must use fields, not form controls.

Also, problem with subform pulling value from main form is the subform actually loads first, which means the values on main form are not available to the subform calcs.

Change subform RecordSource to:

SELECT CostDetails.*, Costings.TotHrs, Costings.DayHours, Costings.Employees FROM Costings RIGHT JOIN CostDetails ON Costings.ItemID = CostDetails.ItemID;

Then calculate Quantity:
=IIf([Unit]="Hour",[TotHrs],IIf([Unit]="Day",RoundUp([TotHrs]/[DayHours]),IIf([Unit]="Employee",[Employees],IIf([Unit]="Group",1,Null))))

And the Sum():
=Sum(Nz(IIf([Unit]="Hour",[TotHrs],IIf([Unit]="Day",RoundUp([TotHrs]/[DayHours]),IIf([Unit]="Employee",[Employees],IIf([Unit]="Group",1,Null))))*[Rate],0))
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:55
Joined
May 7, 2009
Messages
19,247
you may also try this.
added a function to compute the "Quantity" (see modUtil).
added a query and calls the function.
make the query as the recordsource of your subform.
modified the total cost textbox.
 

Attachments

  • Database.zip
    88.5 KB · Views: 87

aymarhoon

Registered User.
Local time
Yesterday, 18:55
Joined
Sep 18, 2018
Messages
10
Thank you very much, both solutions worked very well.

I have another question... How can I make the incremental change of the spinner button by 0.1 not a whole number?

Thanks a million times
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:55
Joined
May 7, 2009
Messages
19,247
open costing form in design view.
go to vba (alt-f11), then change the increment:
Code:
Option Compare Database
Option Explicit
Public varAct As Long

Private Sub SpinBtnHrs_Updated(Code As Integer)
varAct = Me.DayHours
Select Case SpinBtnHrs
    Case Is < varAct
      Me.DayHours = Me.DayHours - 0.1 '1
    Case Is > varAct
     Me.DayHours = Me.DayHours + 0.1 '1
End Select
Me.Dirty=False
[Forms]![frmCostings]![frmCostings_sfrm].Requery
End Sub

Private Sub SpinBtnProf_Updated(Code As Integer)
varAct = Me.ProfitMargin
Select Case SpinBtnProf
    Case Is < varAct
      Me.ProfitMargin = Me.ProfitMargin - 0.1 '1
    Case Is > varAct
     Me.ProfitMargin = Me.ProfitMargin + 0.1 '1
End Select
Me.Dirty=False
Forms!frmCostings_sfrm.Form.Requery
End Sub

Private Sub SpinBtnTrns_Updated(Code As Integer)
varAct = Me.Trainees
Select Case SpinBtnTrns
    Case Is < varAct
      Me.Trainees = Me.Trainees - 0.1 '1
    Case Is > varAct
     Me.Trainees = Me.Trainees + 0.1 '1
End Select
Me.Dirty=False
[Forms]![frmCostings]![frmCostings_sfrm].Requery
End Sub
 

Users who are viewing this thread

Top Bottom