473,406 Members | 2,816 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,406 software developers and data experts.

Solved: Product Calculation

I know there isn't a native function for calculating the product in Access like there is in Excel, but I'm trying to incorporate our various spreadsheets into our database and therefore I need this capability.

I found this function:
Expand|Select|Wrap|Line Numbers
  1. Function Product(strField As String, strTable As String, _
  2. Optional strCriteria As String) As Double
  3. Dim rs As DAO.Recordset
  4. Dim strSql As String
  5. Dim dblResult As Double
  6.  
  7. 'Build the SQL string.
  8. strSql = "SELECT " & strField & " FROM " & strTable & _
  9. " WHERE (" & strField & " Is Not Null) "
  10. If strCriteria <> vbNullString Then
  11. strSql = strSql & " AND (" & strCriteria & ")"
  12. End If
  13.  
  14. 'Loop through the recordset.
  15. Set rs = DBEngine(0)(0).OpenRecordset(strSql & ";")
  16. If rs.RecordCount > 0 Then
  17. dblResult = rs(strField)
  18. rs.MoveNext
  19. Do While Not rs.EOF
  20. dblResult = dblResult * rs(strField)
  21. rs.MoveNext
  22. Loop
  23. End If
  24. rs.Close
  25.  
  26. Product = dblResult
  27. End Function
I saved it, compiled and tried to run it with
Expand|Select|Wrap|Line Numbers
  1. =Product("increase","ppincreases")
and got:
"The object doesn't contain the automation object 'product'"

Can someone spot an obvious mistake, or point me in the direction for another alternative? I've found very few and none seem to work.

Thanks
Mandi
Mar 24 '09 #1
1 1209
NeoPa
32,556 Expert Mod 16PB
Thanks for updating Mandi.

It's probably better to post the solution though. Many will miss the edit note you left indicating that your problem was related to naming the procedure the same as the module it was created in (In this case both named [Product]).
Mar 24 '09 #2

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

Similar topics

1
by: Andreas Paasch | last post by:
I've got somehow a little peculiar problem and can't seem to find the right solution so I could use a hand/hint or two. On toppings.php I have - among others: <a...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
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...
19
by: Mountain | last post by:
I would like opinions on whether this solution could be important and whether anyone knows if it is already solved. (I would also like to know if anyone thinks it cannot be solved.) First, we...
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...
4
by: blg002 | last post by:
All I am trying to do is dynamically fill the "Your Price" field with a number that is the product of the value of "acres" "regularity" and 10. The annoying part is I had it working yesterday and...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.