this loop isnt happening.

G

Guest

Hello,
Have a problem wth a form control im trying to populate from values on
another form, usually id have put in

Forms![Moneyform]![payment] = Me![TotalPayment]
but there are many forms with this and i thought about putting it in a
function, soi have a case statement that supplies where the data is going and
a variable that supplies the data to be inserted into it.


Basically ive got this inside the loop:

<!--
If CurrentProject.AllForms("Moneyform").IsLoaded = True Then
strTarget = Charge
-->

where

<!--
strTarget = "Forms![MoneyForm]![" & strbox & "]"
-->

and strbox is the result of a case block.

This should reference that control which is of the correct datatype.
and 'charge' is an currency datatype that holds a value from the form that
called this funciton.
when i use the debugger i can see that its evaluated strTarget correctly, as
in it says something like 'Forms![MoneyForm]![payment]' but im not sure its
evaluating it as a reference to a control or as a string which it cant
assign the currency value to.

again with thanks

Amit
 
D

Dirk Goldgar

"DowningDevelopments" <[email protected]>
wrote in message
Hello,
Have a problem wth a form control im trying to populate from values on
another form, usually id have put in

Forms![Moneyform]![payment] = Me![TotalPayment]
but there are many forms with this and i thought about putting it
in a function, soi have a case statement that supplies where the data
is going and a variable that supplies the data to be inserted into it.


Basically ive got this inside the loop:

<!--
If CurrentProject.AllForms("Moneyform").IsLoaded = True Then
strTarget = Charge
-->

where

<!--
strTarget = "Forms![MoneyForm]![" & strbox & "]"
-->

and strbox is the result of a case block.

This should reference that control which is of the correct datatype.
and 'charge' is an currency datatype that holds a value from the form
that called this funciton.
when i use the debugger i can see that its evaluated strTarget
correctly, as in it says something like 'Forms![MoneyForm]![payment]'
but im not sure its evaluating it as a reference to a control or as a
string which it cant assign the currency value to.

again with thanks

Amit

I think you want something like this:

If CurrentProject.AllForms("Moneyform").IsLoaded = True Then
Forms!MoneyForm.Controls(strbox) = Charge
End If
 
D

Dan Artuso

HI,
First of all, you don't show us how the variable is declared.
You have to declare it as the type you want it be, *not* a string for example.
So if strTarget is supposed to be a control, declare it as one (and call it ctlTarget or something)

If you want to refer to a control on a form using a variable:
Forms!MoneyForm(strbox)
 
W

Wayne Morgan

With what you have, you're actually trying to assign the value of Charge to
strTarget with the statement:
strTarget = Charge

Instead, you need to assign Charge to the control on the form. Try this
instead:

Forms!MoneyForm.Controls(strbox) = Charge

This uses one the alternate syntaxes of referring to an object. There are 3
syntaxes commonly used:

Forms!MyForm
Forms(1)
Forms("MyForm")

The third one is what I'm using. The default collection for a form is
Controls, so you don't have to specify it when using the !, but can instead
just give the name of a control. When using one of the other two syntaxes,
you need to specify the collection. The string in the third example has been
replaced with a string variable for your situation.

--
Wayne Morgan
MS Access MVP


DowningDevelopments said:
Hello,
Have a problem wth a form control im trying to populate from values on
another form, usually id have put in

Forms![Moneyform]![payment] = Me![TotalPayment]
but there are many forms with this and i thought about putting it in a
function, soi have a case statement that supplies where the data is going
and
a variable that supplies the data to be inserted into it.


Basically ive got this inside the loop:

<!--
If CurrentProject.AllForms("Moneyform").IsLoaded = True Then
strTarget = Charge
-->

where

<!--
strTarget = "Forms![MoneyForm]![" & strbox & "]"
-->

and strbox is the result of a case block.

This should reference that control which is of the correct datatype.
and 'charge' is an currency datatype that holds a value from the form that
called this funciton.
when i use the debugger i can see that its evaluated strTarget correctly,
as
in it says something like 'Forms![MoneyForm]![payment]' but im not sure
its
evaluating it as a reference to a control or as a string which it cant
assign the currency value to.

again with thanks

Amit
 

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