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

calculation question

166 100+
I have an unbound text box which I use to get a calculation, called DM_SampleWt. This text box's control source is:
=GetSize([cbo_matTypeID],Nz([matBatchweight],0),[Form].[Parent]![txtpan],[Form].[Parent]![cbo_panID].[column](2))
I have written a function that will get the required sample weight of a material selected from my form
[cbo_matTypeID]- represents a combo box that allows the user to select the material type (bound)
matBatchweight- represents the batchweight of each material (user input, bound)
[txtpan]-bound text box representing the number of pans that need to be made
cbo_panID.column(2)- bound combo box, represents the pansize needed for the job, the column 2 represents the formula used in the calculation needed.

Here is my function:
Public Function GetSize(matType As Integer, BatchWeight As Double, NoOfPans As Double, PanFormulaValue As Double) As Double
'returns the required sample weight, 'DM_ReqSampWt' calculation

Select Case matType
'Cement, Coarse, Fine
Case 1, 2, 3
GetSize = BatchWeight * NoOfPans * PanFormulaValue / 27
Case 4
'Pigment
GetSize = BatchWeight * NoOfPans * PanFormulaValue / 27 / 0.0022
Case Else
GetSize = 0
End Select
End Function

DM_SampleWeight is automatically calculated after all of the above are input. The problem I am having (the function works perfectly) is that for material cement (cbo_matTYpeID = 1), I need to sum the DM_SampleWeight and I can't because I can not get a TOTAL SUM for a calculated value. I tried to use the same function like this:

=GetSize(Sum([cbo_matTypeID]=1),Nz([matBatchweight],0),[Form].[Parent]![txtpan],[Form].[Parent]![cbo_panID].[column](2))

How can I approach this problem? Thank you
Dec 9 '08 #1
1 1520
ADezii
8,834 Expert 8TB
@csolomon
You could try building the Summation Logic into the Function like so, but I have no idea if this will actually work:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetSize(matType As Integer, BatchWeight As Double, NoOfPans As Double, _
  2.                         PanFormulaValue As Double) As Double
  3. 'returns the required sample weight, 'DM_ReqSampWt' calculation
  4. Select Case matType
  5.   'Cement, Coarse, Fine
  6.   Case 1    'Unique case?
  7.     Dim MyDB As DAO.Database
  8.     Dim rstCalc As DAO.Recordset
  9.     Dim dblRunningSum As Double
  10.  
  11.     Set MyDB = CurrentDb()
  12.     'Could also use an SQL Statement as basis for Recordeset ([Type] = 1)
  13.     Set rstCalc = MyDB.openrecordset("tblCalculation", dbOpenForwardOnly)
  14.  
  15.     With rstCalc
  16.       Do While Not rstCalc.EOF
  17.         If ![Type] = 1 Then
  18.           dblRunningSum = dblRunningSum + (![BatchWeight] * ![NumOfPans] _
  19.                           * ![PanFormulaValue] / 27)
  20.         End If
  21.           .MoveNext
  22.       Loop
  23.       GetSize = dblRunningSum    'Set the Function = the Aggregate Total
  24.     End With
  25.     rstCalc.Close
  26.     Set rstCalc = Nothing
  27.   Case 2, 3
  28.     GetSize = BatchWeight * NoOfPans * PanFormulaValue / 27
  29.   Case 4
  30.     'Pigment
  31.     GetSize = BatchWeight * NoOfPans * PanFormulaValue / 27 / 0.0022
  32.   Case Else
  33.     GetSize = 0
  34. End Select
  35. End Function
Dec 10 '08 #2

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

Similar topics

2
by: rodger | last post by:
hi all, I have a form with two text boxes, a go button and a formula in the code to perform a calculation a value is entered in one text box, and press buttonm a result is computed which is...
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...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
3
by: linq936 | last post by:
I have some algorithm dealing with unsigned int calculation a lot, I am trying to add some check for overflow. The initial thinking was very easy, just do something like this, int...
6
by: David | last post by:
Hi, I have the following calculation I am trying to work out ..... Not sure how ? Variable 1 = minstock Variable 2 = oDict(oKey) I need to test if my variable 'minstock' <= 40% of...
1
by: gjoneshtfc | last post by:
Hello, I have an asp page that is a table. In the table the end column is a calculation of other values, for example: ...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.