Variable as part of controlname

R

RW

I'm setting some values of controls in VB. I am trying to use a variable to
store part of the controlname (everything except the controlname itself) and
am not having much success. Here is what I am trying to do:

Dim SubPath as Variant
SubPath = "Forms![Main Form]![SubForm Name]!"

SubPath & "[Total]" = (SubPath & "[1st Value]") *2


The above is an example. I have numerous fields to populate and would like
to use a variable for part of the name if possible. How is this done?
 
A

Allen Browne

You can try CallByName, but I generally find it easier to pass an object
rather than a string like that, e.g.:
Dim frm As Form
Set frm = Forms![Main Form]![SubForm Name].Form

Then pass frm to the next process, which can use it in these 2 ways:
frm!Total = frm.Controls("[1st Value") * 2
 

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