473,395 Members | 1,629 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,395 software developers and data experts.

Problems with calculated control in subform footer

I have the calculation located in the footer of the subform.
There is sometimes no rows in this form so I have used Allen Browne's IIF(FormHasData([form]),calculation,0) syntax to show a zero if there aren't any rows to calculate on.

Consequently I copied his public function

Expand|Select|Wrap|Line Numbers
  1. Public Function FormHasData(frm As Form) As Boolean
  2. 'Purpose: Return True if the form has any records (other than new one).
  3. ' Return False for unbound forms, and forms with no records.
  4. 'Note: Avoids the bug in Access 2007 where text boxes cannot use:
  5. ' [Forms].[Form1].[Recordset].[RecordCount]
  6. On Error Resume Next 'To handle unbound forms.
  7. FormHasData = (frm.Recordset.RecordCount <> 0&)
  8. End Function
  9.  
  10. 'Notes
  11.  
  12. ' 1. Leave the [Form] part of the expression as it is (i.e. do not substitute the name of your form.)
  13. ' 2. For Access 97 or earlier, use RecordsetClone instead of Recordset in the function.
  14. ' 3. A form with no records still has display problems. The workaround may not display the zero, but it should suppress the #Error.


Other relevant function (for calculating extended price):

CODE
Expand|Select|Wrap|Line Numbers
  1. Public Function CalcExtension(ByVal Quantity as integer, ByVal Price As Currency, ByVal DiscountPercent As Integer) As Currency
  2.  
  3. Dim Extension as Currency
  4. Dim Discount as Double
  5.  
  6. Extension = Quantity * Price
  7. Discount = DiscountPercent / 100
  8. CalcExtension = Extension - (Extension * Discount)
  9.  
  10. End Function


Form is bound: tblOrderDetails

Two calculations:

First: summing the quantities
Control Name: txtqty
Control Source: tblOrderDetails.qty (long integer)

Attempted: =IIF(FormHasData([form]), sum([qty]),0)
Result: 0 when no records, #error when there ARE records


Second: summing the extended price
Control Name: txtExtension (but it is calculated using a function so I have put in the calculation rather than the control)
Involved Controls: txtqty (tblOrderDetails.qty -- long integer); txtDetailsPrice (tblOrderDetails.Price -- Currency); txtDiscount (tblorderDetails.DiscountAmnt -- long integer)

Attempted: =IIF(FormHasData([Form]),Sum(CalcExtension(nz([txtQty],0),Nz([txtDetailsPrice],0
),nz([txtDiscount],0))),0)
Result: 0 when no records, #error when there ARE records
Note: =CalcExtension(nz([txtQty],0),Nz([txtDetailsPrice],0),nz([txtDiscount],0)) is working well in my txtExtension control

I did try opening the subform outside of the parent/child relationship so it would have records (just chose sfrmOrderDetails from the Object List) and tried the straight ahead =sum([qty]) and I got the #error message.

I just don't get it. This database has been compiled and compacted and repaired repetitively.

Why oh why???
Dec 14 '10 #1
1 2868
I've discovered (by messing around with this subform outside of the master form) that the =sum([Qty]) works great as long as the other one is absent --> which tells me that the problem is in the other (sum(calcextension)) one. Can you please look at that syntax and tell me if you notice anything glaring?

Thanks
Dec 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tony Williams | last post by:
I have a form with a tabcontrol which has a number of pages. I want to check the value of a calculated control on one page with a calculated control on another page. The calculated control...
6
by: dhowell | last post by:
I have a "form" and "subform" where I would like a calculated control on the form which sums the values of a datasheet column of the subform. (datasheet on subform may have a variable number of...
3
by: mahsa | last post by:
Hi,How can I access to checkbox control in footer template of datalist and fire the selectedchangeindex event? -- Regards mahsa
0
by: 00_ChInkPoIntD12 | last post by:
Is there any box wrapping control? so that I can put stuff in the box so that it looks more professional in a page. I am not sure what they call. It seems stupid to me to use "Header" and...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
2
by: PrimeHawk | last post by:
I am attempting to add a calculated control that counts the number of records displayed in a subform. I have two seprate tabs, hopefully it will not change the value if I switch between the tabs. I...
17
by: MariaTorvalds | last post by:
I have a problem where if I use a calculated control, for example =Date()) on my form, PLUS I have a subform on a tab control on the same form, then when I refresh the record (by menu command or VBA...
2
by: csolomon | last post by:
Hello: I would like to use information on one form to populate another form. There are 2 controls I would like to transfer; a list box control and a text box control. both are unbound controls...
3
wordbrew
by: wordbrew | last post by:
Hello all, I searched the forums as much as I can and haven't found a viable solution. I have a subform that filters the records by Publisher. In the subform I have a calculated control...
29
by: Bigdaddrock | last post by:
I have tried using the SetValue Macro to assign the value of a calculated control to another BOUND Control on the same form but have not been successful. I followed the exact format shown in MS...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.