Retrun to previous focus field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I have a form with 120 textbox controls, each of which has a label
hiding a command button which when clicked, goes through a series of
functions to get text data based on user choices, MyString. I then wish to
return to the original form (still open) original text box, and set the focus
back to it. How can I do this programically?
For eg: User clicks MyControl on frmMyDataEntry. MyControl is set
equal to varControlName. Functions run and text returned is strMyString
along with varControlName. I try to put it back into txbMyControl using:
Me.varControlName = strMyString
and I've tried
[Forms]![fmrMyDataEntry]![varControlName] = strMyString
where varControlName is a string type variable.
Neither of these work. I've also tried:
[Forms]![frmMyDataEntry]![(varControlName)] = strMyString - NOPE.
When I do a programming aside and just set focus manually, it accepts the
strMyString with no problem. What can I do here? What am I doing wrong? I
do not want to write separate procedures for each of the 120 controls.

Thanks in advance. It's probably an easy solution I've just not run into
before.
 
Hi Kincaid,

I'm not sure I understand the situation but can think of two things.

1) If you want to manipulate a control whose name is in the variable
varControlName, use the syntax
Me.Controls(varControlName).Value = strMyString
or
Forms("frmMyDataEntry").Controls(varControlName) = ...
depending on whether the code is in the form's own code module or in
another module.

2) If varControlname is a string variable declared in the module of one
form, it's not accessible from other modules. If you want to change its
value from code running in another module, one simple way is to replace
the variable with a textbox control (hidden, if you like) which you can
access from other forms using the syntax above.

Hi. I have a form with 120 textbox controls, each of which has a label
hiding a command button which when clicked, goes through a series of
functions to get text data based on user choices, MyString. I then wish to
return to the original form (still open) original text box, and set the focus
back to it. How can I do this programically?
For eg: User clicks MyControl on frmMyDataEntry. MyControl is set
equal to varControlName. Functions run and text returned is strMyString
along with varControlName. I try to put it back into txbMyControl using:
Me.varControlName = strMyString
and I've tried
[Forms]![fmrMyDataEntry]![varControlName] = strMyString
where varControlName is a string type variable.
Neither of these work. I've also tried:
[Forms]![frmMyDataEntry]![(varControlName)] = strMyString - NOPE.
When I do a programming aside and just set focus manually, it accepts the
strMyString with no problem. What can I do here? What am I doing wrong? I
do not want to write separate procedures for each of the 120 controls.

Thanks in advance. It's probably an easy solution I've just not run into
before.
 
Excellent suggestions, John. Thanks much!
Both work well and I'll use both, actually. Thanks again.

John Nurick said:
Hi Kincaid,

I'm not sure I understand the situation but can think of two things.

1) If you want to manipulate a control whose name is in the variable
varControlName, use the syntax
Me.Controls(varControlName).Value = strMyString
or
Forms("frmMyDataEntry").Controls(varControlName) = ...
depending on whether the code is in the form's own code module or in
another module.

2) If varControlname is a string variable declared in the module of one
form, it's not accessible from other modules. If you want to change its
value from code running in another module, one simple way is to replace
the variable with a textbox control (hidden, if you like) which you can
access from other forms using the syntax above.

Hi. I have a form with 120 textbox controls, each of which has a label
hiding a command button which when clicked, goes through a series of
functions to get text data based on user choices, MyString. I then wish to
return to the original form (still open) original text box, and set the focus
back to it. How can I do this programically?
For eg: User clicks MyControl on frmMyDataEntry. MyControl is set
equal to varControlName. Functions run and text returned is strMyString
along with varControlName. I try to put it back into txbMyControl using:
Me.varControlName = strMyString
and I've tried
[Forms]![fmrMyDataEntry]![varControlName] = strMyString
where varControlName is a string type variable.
Neither of these work. I've also tried:
[Forms]![frmMyDataEntry]![(varControlName)] = strMyString - NOPE.
When I do a programming aside and just set focus manually, it accepts the
strMyString with no problem. What can I do here? What am I doing wrong? I
do not want to write separate procedures for each of the 120 controls.

Thanks in advance. It's probably an easy solution I've just not run into
before.
 
Back
Top