Hi
I have a query off a database that works fins and displays a list of 4 numbers in the query in seperate fields, however i only want 1 field to be displayed and that wants to be the PRODUCT of the other 4 i.e. field1 * field2 * field3 * field4.....at some point this could need to be more numbers. Excel has an easy function "=PRODUCT" is there away of doing this in Acess?????
9 2755
Hi
I have a query off a database that works fins and displays a list of 4 numbers in the query in seperate fields, however i only want 1 field to be displayed and that wants to be the PRODUCT of the other 4 i.e. field1 * field2 * field3 * field4.....at some point this could need to be more numbers. Excel has an easy function "=PRODUCT" is there away of doing this in Acess?????
__1. Create a New Query. __2. Place the [Field1], [Field2], [Field3], and [Field4] Fields into the Query Grid. __3. Create a Calculated Field called Total (see code snippet). __4. Deselect the Show Box for Fields 1, 2, 3, and 4. __5. Run the Query ==> Only the Total Field will be visible and will be the Product of the 4 other Fields. - Total: ([Field1]*[Field2]*[Field3]*[Field4])
Thanks for the speedy reply, but not quite what i was after, the fields i want the product of are on seperate records, so in the query there could just be for example 2 records filtered off, or there could be 5 filtered off and i want the product of the field regardless of how many potential records there is, hope that makes sense. Any Ides???
Thanks for the speedy reply, but not quite what i was after, the fields i want the product of are on seperate records, so in the query there could just be for example 2 records filtered off, or there could be 5 filtered off and i want the product of the field regardless of how many potential records there is, hope that makes sense. Any Ides???
More complicated scenario. Post Query results illustrating exactly what you are looking for and I'll check back in later.
Multiple | FixtureID | GameDate | Odds | ResultHomeAwayDraw | Win
5 | 1 24/03/2007 140 Home 0
10 1 24/03/2007 140 Home 0
10 7 24/03/2007 130 Home 0
70 1 24/03/2007 140 Home 1
70 5 24/03/2007 200 Home 0
70 6 24/03/2007 120 Home 0
This is the list of the current query, where the "multiple" colum = 70 for example i want the 140 * 200 * 120 displayed.....i.e. where the "Multiple" Colum = 10 then i want 140 * 130 displayed.........etc so then i can run another query with just the product of the odds colum, if all that makes sense, i thought it would be easy!!!!! but its not!!!
Multiple | FixtureID | GameDate | Odds | ResultHomeAwayDraw |
5 | 1 | 24/03/2007 | 140 | Home
10 | 1 | 24/03/2007 | 140 | Home
10 | 7 | 24/03/2007 | 130 | Home
70 | 5 | 24/03/2007 | 140 | Home
70 | 5 | 24/03/2007 | 200 | Home
70 | 6 | 24/03/2007 | 120 | Home
Multiple | FixtureID | GameDate | Odds | ResultHomeAwayDraw |
5 | 1 | 24/03/2007 | 140 | Home
10 | 1 | 24/03/2007 | 140 | Home
10 | 7 | 24/03/2007 | 130 | Home
70 | 5 | 24/03/2007 | 140 | Home
70 | 5 | 24/03/2007 | 200 | Home
70 | 6 | 24/03/2007 | 120 | Home
Let me think it over for a little and I'll get back to you.
Multiple | FixtureID | GameDate | Odds | ResultHomeAwayDraw |
5 | 1 | 24/03/2007 | 140 | Home
10 | 1 | 24/03/2007 | 140 | Home
10 | 7 | 24/03/2007 | 130 | Home
70 | 5 | 24/03/2007 | 140 | Home
70 | 5 | 24/03/2007 | 200 | Home
70 | 6 | 24/03/2007 | 120 | Home
__1. I don't know the name of your Table but for the sake of simplicity, I'll call it tblGames. __2. Create a Query call qryProduct whic will consist of 1 Field for now, namely [Multiple]. __3. Set the Sort Order of the [Multiple] Field in qryProduct to Ascending. __4. Set the Unique Values Property to yes for qryProduct. This Query will now generate a list of 'Unique' [Multiple] values. __5. Copy and Paste the following Function to a Standard Code Module. - Public Function fCalculateProduct(intMultiple As Long) As String
-
Dim intNoOfMultiples As Integer, intCounter As Integer, lngProduct As Long
-
-
'Calculate the # of Records for the [Multiple]
-
intNoOfMultiples = DCount("*", "tblGames", "[Multiple]=" & intMultiple)
-
-
lngProduct = 1 'Initialize
-
-
If intNoOfMultiples = 1 Then
-
'Only 1 Record - just return [Odds]
-
fCalculateProduct = Format$(DLookup("[Odds]", "tblGames", "[Multiple]=" & intMultiple), "Standard")
-
Else
-
'Now we got work to do
-
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("SELECT * From tblGames WHERE [Multiple] =" & intMultiple, dbOpenSnapshot)
-
MyRS.MoveFirst
-
Do While Not MyRS.EOF
-
lngProduct = lngProduct * MyRS![Odds]
-
MyRS.MoveNext
-
Loop
-
fCalculateProduct = Format$(lngProduct, "Standard")
-
MyRS.Close
-
End If
-
End Function
__6. Create a Calculate Field in qryProduct called Product. This Calculated Field will call the fCalculateFunction() and pass to it the [Multiple] Field. It will look like this in the QBE Grid. - Multiple Product: fCalculateProduct([Multiple])
-
tblGames
-
Ascending
__7. Run the Query. OUTPUT: - Multiple Product
-
5 140.00
-
10 18,200.00
-
70 3,360,000.00
-
89 1,521,275,736.00
NOTE: 89 was my own little Test Value. If you have any other questions, please feel free to ask.
Thanks for your help there!!! I just can't quite get it to work, i get an error from the standard Module, on the line "myRs.MoveFirst" it errors there saying "no current record" any ideas what it could be? i've used all the same names as you in your example??
Thanks for your help there!!! I just can't quite get it to work, i get an error from the standard Module, on the line "myRs.MoveFirst" it errors there saying "no current record" any ideas what it could be? i've used all the same names as you in your example??
That Error indicates that the SQL Statement did not return any Records but if you made it to this line, there logically must be because intNoOfMultiples cannot = 0 since it is being passed to the Function(), and the case has already been accounted for where intNoOfMultiples = 1. Are [Multiple] and [Odds] Required Fields? Do Records actually exist in tblGames and are the Field Names identical? Also, check for a Typo in the OpenRecordset() line. Let me know how you made out.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Zsolt Koppany |
last post by:
Hi,
I use dynamic menus and would like to know how I can figure out the height
of a text (for exalple "Product"). I need it to calculate text positions.
Zsolt
|
by: Sven Seljom |
last post by:
I want to take the value from one form-field, deduct the VAT and return the
value in another form-field. I have made a Public Function for this and
attached it to the text-box. Can anybody help me...
|
by: Eric Slan |
last post by:
Hello All:
I'm having a problem that's been baffling me for a few days and I seek
counsel here.
I have an Access 2000 DB from which I want to run several reports. These
reports are...
|
by: carla |
last post by:
I am using Access 2000 and have a table, tblCurrent. That table
contains several fields - three of those fields are ,
and . What I want to accomplish in my data entry form, is
first entering the...
|
by: enrique.rojas |
last post by:
Hello
I have been trying to make an SQL statement that will get the the last
product audited in a database.
The problem is that this database holds data for several emplyees that
audit...
|
by: ChaseCox |
last post by:
Hi all,
I have a problem that I have been looking at for a couple days now and I can not quite get it to work.
I would like to calculate the cumulative percent failure of a certain product in...
|
by: ollielaroo |
last post by:
Hi guys,
Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site.
My problem is...
|
by: rrstudio2 |
last post by:
I am using the following vba code to calculate the median of a table
in MS Access:
Public Function MedianOfRst(RstName As String, fldName As String) As
Double
'This function will calculate the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
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,...
|
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,...
|
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...
| |