Putting calculated figure on form

A

Annie

Hi. I calculated "curTotal" in VB. Can I put this value
on my form? The curTotal is code on the subform. I'd
like curTotal to appear probably on the mainform as a
field.

Possible? How would I do that? Thanks, Annie
 
A

Annie

Thanks for the reply. I think I need a bit of
clarification because I couldn't make it work.

I placed RunningTotal field on MainForm. Then in the VB
code for the subform (where I calculated curTotal)I put
in:
forms!MainForm.RunningTotal= curTotal

On RunningTotal do I need a control source? I tried
=curTotal but that didn't work. Somehow I missing the
actual link between RunningTotal(field) on the MainForm
and curTotal (VB calc on the subform). Sorry. Thanks
for the additional help! Annie
 
G

Guest

It should have worked so it might be the names of your forms or the name of
your control. also what it the error you are getting or what is not working?

Here are some examples:
There are a number of ways to wright this code.
If you look at the vb explorer you see the name of your form look something
like this: Form_Form1
i can't remember why they do this but that is there naming convention
you can use that exact name or you can use your short version by putting []
around the name. This is also necessary if you have spaces in the name.

use access names:
Form_Form1!Text0 = "cool"
use your short names (Recommended):
[Forms]![Form1]![Text0] = "cool2"

you can also use the "." to access the properties of the form or controls.

Form_Form1.Text0.Value = "cool"
[Forms]![Form1]![Text0].Value = "cool2"

The .value is the default property, so if you don't use it VB figuers this
out and passes your data to that property like in the first 2 examples

You can also do combinations of syntax which is why it gets so confusing for
some people.

[Forms]!Form1!Text0 = "cool2"
[Forms]![Form1]![Text0] = "cool3"
[Forms]![Form1]!Text0.Value = "cool4"

All of the above examples were for accessing the main form from the subform


Also if you want to reference the form u are currently in the the me. is
usefull

me.Text0.Value = "to cool"

if you want to access the subform form the main form you can do something
like this:

[Form2].Form![Text1] = 2
[Form2].[Form]![Text1] = 3
Me.[Form2]![Text1].Value = 4

Your code was this:
forms!MainForm.RunningTotal= curTotal

if i were to use my example then it would look like this:
Forms!Form1.Text0 = curTotal

Also this code should be in the subform


i hope this helps
Good Luck!
 
A

Annie

Thanks for the syntax lesson! Annie
-----Original Message-----
It should have worked so it might be the names of your forms or the name of
your control. also what it the error you are getting or what is not working?

Here are some examples:
There are a number of ways to wright this code.
If you look at the vb explorer you see the name of your form look something
like this: Form_Form1
i can't remember why they do this but that is there naming convention
you can use that exact name or you can use your short version by putting []
around the name. This is also necessary if you have spaces in the name.

use access names:
Form_Form1!Text0 = "cool"
use your short names (Recommended):
[Forms]![Form1]![Text0] = "cool2"

you can also use the "." to access the properties of the form or controls.

Form_Form1.Text0.Value = "cool"
[Forms]![Form1]![Text0].Value = "cool2"

The .value is the default property, so if you don't use it VB figuers this
out and passes your data to that property like in the first 2 examples

You can also do combinations of syntax which is why it gets so confusing for
some people.

[Forms]!Form1!Text0 = "cool2"
[Forms]![Form1]![Text0] = "cool3"
[Forms]![Form1]!Text0.Value = "cool4"

All of the above examples were for accessing the main form from the subform


Also if you want to reference the form u are currently in the the me. is
usefull

me.Text0.Value = "to cool"

if you want to access the subform form the main form you can do something
like this:

[Form2].Form![Text1] = 2
[Form2].[Form]![Text1] = 3
Me.[Form2]![Text1].Value = 4

Your code was this:
forms!MainForm.RunningTotal= curTotal

if i were to use my example then it would look like this:
Forms!Form1.Text0 = curTotal

Also this code should be in the subform


i hope this helps
Good Luck!

Annie said:
Thanks for the reply. I think I need a bit of
clarification because I couldn't make it work.

I placed RunningTotal field on MainForm. Then in the VB
code for the subform (where I calculated curTotal)I put
in:
forms!MainForm.RunningTotal= curTotal

On RunningTotal do I need a control source? I tried
=curTotal but that didn't work. Somehow I missing the
actual link between RunningTotal(field) on the MainForm
and curTotal (VB calc on the subform). Sorry. Thanks
for the additional help! Annie
.
 
G

Guest

Opps sorry Annie, i was kind of in a hurry so when i saw your post i only
read the clarification part and didn't ready your post as thoroughly as i
should.

You might test to see if your "curTotal" has a value if nothing is being
displayed.
Try putting this in your code before you send it to the main form
msgbox "curTotal = " & curTotal

Also the control on the main form should be unbound which means it has no
control source or nothing in the control source property. That is unless you
want to edit a record in the main form. Then you need to make sure that the
Record Source property in the main form is an editable record source.
Because if its a query then the query might not allow changes to the data
which would cause and error.

The only other thing i can think of is that the event you have your code in
isn't firing. So you the msgbox test should be able to tell you if vb is
even running that line of code.

My apologies for my past mistake as well as any spelling or grammatical
errors.
Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top