mshmyob 904
Recognized Expert Contributor
Going to post this real fast since I have to go out, so I hope I get all the pertenent info in the message.
I have a subform and the results are based on a select query. Results are say like so (just a snippet of the results)
Quarter Value Calculated
4 200 25
3 175 -5
2 180 30
1 150 0
Assume the first 2 columns are derived from my select query.
The 3rd column is the one I need to figure out. It is a formula and just assume I need to subtract the value of Qtr4 from Qtr3 for row 1, subtract Qtr3 from Qtr2 for row 2, etc.
I am drawing a blank how I can accomplish this on the subform. Any direction would be appreciated.
cheers,
19 2367 ADezii 8,834
Recognized Expert Expert
You can create a Calculated Field within the Query comprising the Record Source for the Sub-Form. This Calculated Field would call a Public Function and pass to it the Values in the [Quarter] and [Value] Fields for each Record. Logic would be contained within the Function and it would return an Integer Value representing the difference between the Quarters. I had something like this in mind: - Calculated Field in Query
- Difference:fCalcFormula([Quarter], [Value])
- Function definition:
- Public Function fCalcFormula(bytQuarter As Byte, intValue As Integer) As Integer
-
...logic here
-
End Function
P.S. - You stated that this was a snippet of code, which confused me, since there are only 4 Quarters in a Year. Are multiple Years involved? This wouold change the code logic. When I have time, I'll actually work on a simple template for you.
mshmyob 904
Recognized Expert Contributor
Yes multiple years. I will look at this over the weekend.
Thanks Ade.
cheers,
You can create a Calculated Field within the Query comprising the Record Source for the Sub-Form. This Calculated Field would call a Public Function and pass to it the Values in the [Quarter] and [Value] Fields for each Record. Logic would be contained within the Function and it would return an Integer Value representing the difference between the Quarters. I had something like this in mind:- Calculated Field in Query
- Difference:fCalcFormula([Quarter], [Value])
- Function definition:
- Public Function fCalcFormula(bytQuarter As Byte, intValue As Integer) As Integer
-
...logic here
-
End Function
P.S. - You stated that this was a snippet of code, which confused me, since there are only 4 Quarters in a Year. Are multiple Years involved? This wouold change the code logic.
ADezii 8,834
Recognized Expert Expert
Yes multiple years. I will look at this over the weekend.
Thanks Ade.
cheers,
- tblMshmyob
- Quarter Value
-
1 150
-
2 180
-
3 175
-
4 200
- qryMshmyob
- SELECT tblMshmyob.Quarter, tblMshmyob.Value, fCalcDiff([Quarter],[Value]) AS Difference
-
FROM tblMshmyob
-
ORDER BY tblMshmyob.Quarter DESC;
- Function Definition
- Public Function fCalcDiff(bytQuarter As Byte, intValue As Integer) As Integer
-
Dim intValPrevQuar As Integer
-
-
If bytQuarter = 1 Then
-
fCalcDiff = 0
-
Else
-
'Calculate the Value for the previous Quarter
-
intValPrevQuar = DLookup("[Value]", "tblMshMyob", "[Quarter] = " & bytQuarter - 1)
-
Select Case bytQuarter
-
Case 2, 3, 4
-
fCalcDiff = [intValue] - intValPrevQuar
-
End Select
-
End If
-
End Function
- OUTPUT
- Quarter Value Difference
-
4 200 25
-
3 175 -5
-
2 180 30
-
1 150 0
- P.S. - Multiple Years are not taken into consideration.
mshmyob 904
Recognized Expert Contributor
Thanks Ade. This looks like it will work for me. There is more to it than years and quarters and the formula is also more complicated than subtracting but I am sure with your suggestion I can make it all work, since I have done it outside of the subform :). I was just drawing a blank on getting it to work inside the subform. Your idea looks like it will work. The fact that you used a global function is perfect since I am using a global function now for the calculation outside the subform.
I let you know after the weekend.
cheers, - tblMshmyob
- Quarter Value
-
1 150
-
2 180
-
3 175
-
4 200
- qryMshmyob
- SELECT tblMshmyob.Quarter, tblMshmyob.Value, fCalcDiff([Quarter],[Value]) AS Difference
-
FROM tblMshmyob
-
ORDER BY tblMshmyob.Quarter DESC;
- Function Definition
- Public Function fCalcDiff(bytQuarter As Byte, intValue As Integer) As Integer
-
Dim intValPrevQuar As Integer
-
-
If bytQuarter = 1 Then
-
fCalcDiff = 0
-
Else
-
'Calculate the Value for the previous Quarter
-
intValPrevQuar = DLookup("[Value]", "tblMshMyob", "[Quarter] = " & bytQuarter - 1)
-
Select Case bytQuarter
-
Case 2, 3, 4
-
fCalcDiff = [intValue] - intValPrevQuar
-
End Select
-
End If
-
End Function
- OUTPUT
- Quarter Value Difference
-
4 200 25
-
3 175 -5
-
2 180 30
-
1 150 0
- P.S. - Multiple Years are not taken into consideration.
NeoPa 32,556
Recognized Expert Moderator MVP
Thanks Ade.
Just to clarify - you may have seen references to Ade in threads with ADezii involved. That's generally a reference to me (Abbreviation of Adrian in real life as ADezii knows).
I can't say too much about another member's personal details, but I do know that Ade is not an abbreviation for ADezii.
ADezii 8,834
Recognized Expert Expert
Just to clarify - you may have seen references to Ade in threads with ADezii involved. That's generally a reference to me (Abbreviation of Adrian in real life as ADezii knows).
I can't say too much about another member's personal details, but I do know that Ade is not an abbreviation for ADezii.
You mean I'm not Ade!
NeoPa 32,556
Recognized Expert Moderator MVP
You KNOW I can never be as uncomplicated as that ADezii!
mshmyob 904
Recognized Expert Contributor
Sorry Ade and sorry ADe.
cheers,
ADezii 8,834
Recognized Expert Expert
Tou KNOW I can never be as uncomplicated as that ADezii!
I was just laying back and waiting to see how long it would take you to catch on! (LOL).
ADezii 8,834
Recognized Expert Expert
Sorry Ade and sorry ADe.
cheers,
No problem, mshmyob, NeoPa and I are known by many names, not all of them flattering! (LOL).
NeoPa 32,556
Recognized Expert Moderator MVP
I was just laying back and waiting to see how long it would take you to catch on! (LOL).
Of course there should have been quotes - but it only took a second scan to get the gist of what you were trying to say. Almost 5 seconds then :D
mshmyob 904
Recognized Expert Contributor
Finally got back to this problem. Is it possible to reference a recordset inside a module? I have tried the following (and variations) with no luck. -
Set rst = Forms!frmContactInfo!RORDetailsubform.Form.RecordsetClone
-
I have tried it outside the module and it works. Inside a module called by the function you indicated in the select query I get error # 7951 Expression has invalid reference to recodersetclone property.
If I can get a recordset based on my select query it will make my calculation easier.
cheers,
mshmyob 904
Recognized Expert Contributor
OK I modified my query like so -
SELECT tblRORDetail.RORYear, tblRORDetail.RORQtr, tblRORDetail.RORQtrMarket, tblRORDetail.RORQTRCredits, tblAccountType.AccountTypeName, tblRORDetail.RORQTRDebits, fCalcRORQtr(RORYear,RORQtr,RORQtrMarket,RORQtrCredits,RORQTRDebits) AS RORPeriod FROM tblAccountType INNER JOIN tblRORDetail ON tblAccountType.AccountTypeID=tblRORDetail.AccountTypeID WHERE tblRORDetail.ContactID=forms!frmContactInfo.txtClientID AND tblAccountType.AccountTypeID=forms!frmContactInfo.RORDetailsubform.form.cboSelectAccountType ORDER BY tblRORDetail.RORYear DESC , tblRORDetail.RORQtr DESC , tblAccountType.AccountTypeName;
-
What I notice is that it seems to call the function only twice. Once on the first row of the subform and on the last row of the subform. Any row in between does not get called.
The function also only gets called when the value of cboSelectAccountType is = 1 (which is the first accounttype in the table tblAccountType). Any other value the function never gets called.
I will keep looking at it to see where I messed up but if you spot anything please let me know.
cheers,
FishVal 2,653
Recognized Expert Specialist
Obviously, seeing fCalcRORQtr() function code would help spot anything. :)
mshmyob 904
Recognized Expert Contributor
Maybe :)
I figured something out though. If any value such as RORCredits or RORDebits for instance is null then the query actually doesn't seem to call the function. If I put in values of 0 or greater for these 2 fields everything works as it should.
Therefore I will just set my constraints for the fields to be >= 0.
cheers,
Obviously, seeing fCalcRORQtr() function code would help spot anything. :)
FishVal 2,653
Recognized Expert Specialist
Maybe :)
I figured something out though. If any value such as RORCredits or RORDebits for instance is null then the query actually doesn't seem to call the function. If I put in values of 0 or greater for these 2 fields everything works as it should.
Therefore I will just set my constraints for the fields to be >= 0.
cheers,
IMHO, its a bit overkill to set table constraint for the sake of single peace of code not loving Nulls. :)
Did you try to declare function arguments as Variant and handle Nulls inside function logic?
mshmyob 904
Recognized Expert Contributor
Good point Fish. I also do not like settings those types of constraints.
In my module function I changed the dblCredit and dblDebit variables from double to variant and it works without the contraints.
Thanks for the help guys.
cheers,
IMHO, its a bit overkill to set table constraint for the sake of single peace of code not loving Nulls. :)
Did you try to declare function arguments as Variant and handle Nulls inside function logic?
FishVal 2,653
Recognized Expert Specialist
Not a problem.
Good luck.
ADezii 8,834
Recognized Expert Expert
Finally got back to this problem. Is it possible to reference a recordset inside a module? I have tried the following (and variations) with no luck. -
Set rst = Forms!frmContactInfo!RORDetailsubform.Form.RecordsetClone
-
I have tried it outside the module and it works. Inside a module called by the function you indicated in the select query I get error # 7951 Expression has invalid reference to recodersetclone property.
If I can get a recordset based on my select query it will make my calculation easier.
cheers,
The code itself, assigning RecordsetClone to the Object Variable rst is sound ,as long as rst is declared with the proper Scope.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Allen Browne |
last post by:
Subform is based on a single-table query that contains a calculated field:
Amount: Round(CCur(Nz(*,0)),2)
Continuous subform displays this field in a text box named Amount.
As user enters new...
|
by: Phil Stanton |
last post by:
I have a form of club members with a continuous subform on it showing boat
details.
I hold the boat length and beam (in meters) in a table. On the subform I
also calculate and show the imperial...
|
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 one of the...
|
by: tconway |
last post by:
I have an Access program that displays Customer data into a form and
OrderID data into a subform. The totals in the Subform are based on
calculated fields, i.e. the Total Amount field Calculates...
|
by: jburris |
last post by:
I have been through enough of these threads to think that this should
be an easy fix... but, are there circumstances in which the following
code syntax does not work?
=!!.Form! (this is
out of...
| |
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...
|
by: Jimmy Stewart |
last post by:
I want to use a calculated function for the caption on my tab controls. I
used the following code:
Me.Page28.Caption = "Expenses & "]"
This should display the following: " Expenses " where...
|
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...
|
by: royals |
last post by:
Hello Access gurus,
I am a self-taught Access “developer” and have a ton to learn so please allow me to sound stupid. I am using 2003 on a XP platform.
I manage properties for an...
|
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...
|
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: 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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |