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

Problem with Form Calculations

I'm working on Access 2000 at the moment and i've got a small problem in regards to coding a calculation involving a form and a subform.

The form i have is called Player Overall Stats and the problem area is with two text boxes i have created to display win and loss values. The problem arises where i'm trying to find a way to take the value of a result field, which is either win or lose. I'm hoping to convert this into a number, so for example, in the subform there are 2 wins and 1 loss, i'm not entirely sure how to code it so that on the main form there would be 2 in the wins box and 1 in the loss box.

So what i'm trying to do in vba is go through the subform and count wins and losses basically and put these results onto the main form.

Any help you can give me would be appreciated.
May 31 '07 #1
9 1746
puppydogbuddy
1,923 Expert 1GB
I'm working on Access 2000 at the moment and i've got a small problem in regards to coding a calculation involving a form and a subform.

The form i have is called Player Overall Stats and the problem area is with two text boxes i have created to display win and loss values. The problem arises where i'm trying to find a way to take the value of a result field, which is either win or lose. I'm hoping to convert this into a number, so for example, in the subform there are 2 wins and 1 loss, i'm not entirely sure how to code it so that on the main form there would be 2 in the wins box and 1 in the loss box.

So what i'm trying to do in vba is go through the subform and count wins and losses basically and put these results onto the main form.

Any help you can give me would be appreciated.
The following assumes that the detail control on your subform is called [Outcome] , the subform footers are totalWins and totalLosses, and the textboxes on the main form are txtWins and txtLosses

1.To total wins and losses, place two textboxes in the subform footer section:
[totalWins] = Sum(IIf ([Outcome] = “Win”, 1, 0)
[totalLosses] = Sum(IIf ([Outcome] = “Loss”, 1, 0)

2.Have each of your textboxes on the main form get the totals from the subform like this: txtWins.Value = Me!YourSubformContainer.Form![totalWins]
txtLosses.Value = Me!YourSubformContainer.Form![totalLosses]

3.This code goes in the change event for win and loss controls on the subform.
Me.Parent![txtWins].Recalc
Me.Parent![txtLosses].Recalc
May 31 '07 #2
3.This code goes in the change event for win and loss controls on the subform.
Me.Parent![txtWins].Recalc
Me.Parent![txtLosses].Recalc
You mean the event where the wins and losses are calculated?
May 31 '07 #3
You mean the event where the wins and losses are calculated?
Okay, i've put that coding on the on change event for results, so should the result be changed this code should run.

At the moment i've got

In the Wins text box on the main form,

Expand|Select|Wrap|Line Numbers
  1. Wins.Value = Me!Ball Total Subform For Stats.Form![totalWins]
  2.  
And currently in the Total Wins text box i have
Expand|Select|Wrap|Line Numbers
  1. [TotalWins]=Sum(If([Result]=[“Win”],1,0))
  2.  
However i get a runtime error 438 saying the object doesnt support this property or method when i try and edit the result.
May 31 '07 #4
Hi Jhawkins

If you don't specifically need VBA code you could use something similar to a db I have made before. I'm not using a vba code, just an expression as my control source.

I have eliminated fields that do not apply to your problem. And have changed my form name to match yours. If you are wanting vba specifically, please feel free to ignore this completely! :)

theAybaras

Tables
----------
Expand|Select|Wrap|Line Numbers
  1. <b>tblname = tblMain</b>
  2. <i>Field Name; Data Type; Description
  3. mainkey; autonumber; PK
  4. playname; text; (name of player)</i>
  5.  
  6. <b>tblname = tblSub</b>
  7. <i>Field Name; Data Type; Description
  8. subkey; autonumber; PK
  9. sub_mainkey; numeric; FK
  10. winloss; text; (looks up a defined list of "Win", "Loss", "Draw")</i>

Forms
----------
Player Overall Stats
Includes [playname] from tblMain and three unbound fields labeled "Wins" "Losses" and "Draws" as well
as a subform datasheet where you can enter in as many wins losses or draws as you want.

frmSub
Includes [winloss] from tblSub which is a combobox that allows you to select "Win", "Loss" or "Draw".

on Player Overall Stats, my unbound "Wins" control source is:
<i>
Expand|Select|Wrap|Line Numbers
  1. =DCount( "[winloss]", "tblSub", "[winloss] = 'Win' And [sub_mainkey] =  [mainkey]" ),
</i>

on Player Overall Stats, my unbound "Losses" control source is:
<i>
Expand|Select|Wrap|Line Numbers
  1. =Dcount( "[winloss]", "tblSub", "[winloss] = 'Loss' And [sub_mainkey] = [mainkey]" ),
</i>

on Player Overall Stats, my unbound "Draw" control source is:
<i>
Expand|Select|Wrap|Line Numbers
  1. =Dcount( "[winloss]", "tblSub", "[winloss] = 'Draw' And [sub_mainkey] = [mainkey]" ),
</i>

Results.
tblMain.mainkey; tblMain.playname values:
1; Alan Fontaine,
2; Michael Villipando,
3; Jony Shavier

tblSub.subkey; tblSub.sub_mainkey; tblSub.winloss values
1; 1; Loss
2; 1; Loss
3; 1; Win
4; 1; Win
5; 2; Win
6; 2; Draw
7; 2; Loss
8; 2; Win
9; 3; Win
10; 3; Win
11; 3; Win
12; 3; Loss

On my form when I cycle through my records I see the appropriate data in the sub form, and in Player Overall Stats:
Record 1
Alan Fontaine
Subform
Wins; 2
Losses; 2
Draws; 0

Record 2
Michael Villipando
Wins; 2
Losses; 1
Draws; 1

Record 3
Jony Shavier
Wins; 3
Losses; 1
Draws; 0
May 31 '07 #5
puppydogbuddy
1,923 Expert 1GB
Okay, i've put that coding on the on change event for results, so should the result be changed this code should run. That is correct.

At the moment i've got in the Wins text box on the main form,
Wins.Value = Me!Ball Total Subform For Stats.Form![totalWins]
Change to this (put brackets around names that have spaces within)
= Me![Ball Total Subform For Stats].Form![totalWins]

And currently in the Total Wins text box i have
[TotalWins]=Sum(If([Result]=[“Win”],1,0))
Change to this (If to IIf and take out everything to the left of the equal sign):
=Sum(IIf([Result]=[“Win”],1,0))
May 31 '07 #6
Okay, i've put that coding on the on change event for results, so should the result be changed this code should run. That is correct.

At the moment i've got in the Wins text box on the main form,
Wins.Value = Me!Ball Total Subform For Stats.Form![totalWins]
Change to this (put brackets around names that have spaces within)
= Me![Ball Total Subform For Stats].Form![totalWins]

And currently in the Total Wins text box i have
[TotalWins]=Sum(If([Result]=[“Win”],1,0))
Change to this (If to IIf and take out everything to the left of the equal sign):
=Sum(IIf([Result]=[“Win”],1,0))
Okay i've put that code in, and the code below is set to be applied on a result change.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Result_Change()
  2. Me.Parent![Wins].Recalc
  3. End Sub
  4.  
However it brings up the same error as before. It also puts #name? into the wins box and #error into other boxes on that form that do calculations.
May 31 '07 #7
puppydogbuddy
1,923 Expert 1GB
Okay i've put that code in, and the code below is set to be applied on a result change.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Result_Change()
  2. Me.Parent![Wins].Recalc
  3. End Sub
  4.  
However it brings up the same error as before. It also puts #name? into the wins box and #error into other boxes on that form that do calculations.
First, try changing>>> Me.Parent![Wins].Recalc to Parent![Wins].Recalc

If that does not help, then I need you to provide or confirm the following info before going further.

Name of textboxes on Main Form: [Wins] ; [Losses]
Name of Main Form:
Name of SubformControl on Main Form: [Ball Total Subform For Stats]
Name of Subform (the Source obj in the Subform container) :
Name of textbox control in the S/f Detail: [Result]
Name of textbox controls in the S/f footer:[TotalWins]: [TotalLosses]
May 31 '07 #8
First, try changing>>> Me.Parent![Wins].Recalc to Parent![Wins].Recalc

If that does not help, then I need you to provide or confirm the following info before going further.

Name of textboxes on Main Form: [Wins] ; [Losses]
Name of Main Form:
Name of SubformControl on Main Form: [Ball Total Subform For Stats]
Name of Subform (the Source obj in the Subform container) :
Name of textbox control in the S/f Detail: [Result]
Name of textbox controls in the S/f footer:[TotalWins]: [TotalLosses]

Okay that didnt help

The names of the two text boxes are like you say Wins and Losses
The name of the main form is Player Overall Stats
Not sure what you mean by the two next options.
If i'm reading it correctly [Ball Total Subform for Stats] is the name of the subform.
As for the name of the subform control, i'm not entirely sure what you mean.

The rest looks okay.
May 31 '07 #9
puppydogbuddy
1,923 Expert 1GB
Okay that didnt help

The names of the two text boxes are like you say Wins and Losses
The name of the main form is Player Overall Stats
Not sure what you mean by the two next options.
If i'm reading it correctly [Ball Total Subform for Stats] is the name of the subform.
As for the name of the subform control, i'm not entirely sure what you mean.
The rest looks okay.
I noticed I made one syntax error.
Change this: =Sum(IIf([Result]=[“Win”],1,0)) to =Sum(IIf([Result]=“Win”,1,0))

You forgot to tell me whether the change from Me.Parent to Parent above had any effect on the calulations. Also, can the [Result] ever be any thing other than "Win" or "Loss" .....i,e. can result ever be null?

The subform control is the container object on the main form that holds the form that we refer to as the subform. If you put the main form in design view, invoke the property sheet, and then click the along the border between the main Form and what you think of as the subform, you will see the title on the property sheet change to subform/report....this is the subform container on the main form that holds the form that is referred to as the subform from a user perspective. On that container, the first 2 properties you will see are the name (which refers to the name of the SubformControl) and the source object (which refers to the name of the form within the subform container. Both may have the same name or they may have different names, but I need to know which is which.
May 31 '07 #10

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

Similar topics

40
by: Chiwa | last post by:
Hey, Expression: Math.floor(x * 100) / 100 x= 4.1 gives 4.09, why in gods name? While other values for x don't give a problem. Thx in advance
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
2
by: Lloyd Stevens | last post by:
I'm trying to create a report from two queries, one query displays which customers bought a particular product, the quantity and price using the "Enter productID" as parameter While the other is...
11
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
6
by: Sanjay | last post by:
Hi, Is it possible to save all the names/values of a form to another memo textfield before a Insert to the database then when required on another page split that memo textfield into the name and...
7
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the...
5
by: rocknbil | last post by:
Hello everyone! I'm new here but have been programming for the web in various languages for 15 years or so. I'm certainly no "expert" but can keep myself out of trouble (or in it?) most of the time....
7
by: bummerland | last post by:
Hi, I have a problem with the function fmod. Why is fmod(5.7, 0.1) = 0.1 ?? Why is it not 0? tia bummerland
4
by: Truck Estevez | last post by:
So I have this form I created in PHP, to get a general estimate of the cost of my product... right now i have it so whatever you select, be it in a dropdown menu or checkbox, your total is...
1
by: JeffP | last post by:
Have a textbox in a report footer that sums data using Sum. That text box value is used in a few calculations in the footer. Trouble is, if the report has no data then the box simply shows #error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.