can't change focus to main form textbox

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

Guest

I have a main form "A" with a subform "B." When a button, "lock/unlock" on
form A is pressed, one existing button on subform B is set to invisisble and
two other command buttons are set to visible.
Here is the problem:
After one of these command buttons is pressed, another form "C" opens in a
new window where the user can view or edit data. When the user returns to
the main form and subform "B" by closing form "C", the command button they
used to open form C still has the focus.. so when I click the lock/unlock
button on form A, I get the error, "You can't hide a control that has the
focus."

I know there are a few possible solutions to this one. I want to change the
focus to a textbox, "VRM" on the main form A whenever the lock/unlock button
is pressed. In VB for the lock button onclick event I have tried
Me.VRM.SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")

but it doesn't solve the problem. The Me.VRM.SetFocus doesn't seem to have
any effect (in that the control previously pressed still generates the error.)
What am i doing wrong here? Do I need to put something else before the
Me.VRM.SetFocus? (Is it something to do with the fact that the buttons
hidden are in the subform and the lock button is on the main form?) There are
lots of things that are toggled between visible/invisible when the lock
button is pressed and rather than coding each one individually, I just want
to reset the focus to a textbox on the main form when the lock button is
pressed.

TIA
rich
 
Try and set the focus to another object in the subform instead of the main form

Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
 
Thanks for your suggestion Ofer.
Sometimes, the user wll be amending information in textboxes in the main
form (and not those in the subform) after clicking the ock/unlock button.
Is there a way to simply send forcus to the textbox VRM every time the
lock/unlock button is pressed?
thanks
rich

Ofer said:
Try and set the focus to another object in the subform instead of the main form

Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
--
I hope that helped
Good luck


Rich1234 said:
I have a main form "A" with a subform "B." When a button, "lock/unlock" on
form A is pressed, one existing button on subform B is set to invisisble and
two other command buttons are set to visible.
Here is the problem:
After one of these command buttons is pressed, another form "C" opens in a
new window where the user can view or edit data. When the user returns to
the main form and subform "B" by closing form "C", the command button they
used to open form C still has the focus.. so when I click the lock/unlock
button on form A, I get the error, "You can't hide a control that has the
focus."

I know there are a few possible solutions to this one. I want to change the
focus to a textbox, "VRM" on the main form A whenever the lock/unlock button
is pressed. In VB for the lock button onclick event I have tried
Me.VRM.SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")

but it doesn't solve the problem. The Me.VRM.SetFocus doesn't seem to have
any effect (in that the control previously pressed still generates the error.)
What am i doing wrong here? Do I need to put something else before the
Me.VRM.SetFocus? (Is it something to do with the fact that the buttons
hidden are in the subform and the lock button is on the main form?) There are
lots of things that are toggled between visible/invisible when the lock
button is pressed and rather than coding each one individually, I just want
to reset the focus to a textbox on the main form when the lock button is
pressed.

TIA
rich
 
Try this
Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")
Me.VRM.SetFocus

--
I hope that helped
Good luck


Rich1234 said:
Thanks for your suggestion Ofer.
Sometimes, the user wll be amending information in textboxes in the main
form (and not those in the subform) after clicking the ock/unlock button.
Is there a way to simply send forcus to the textbox VRM every time the
lock/unlock button is pressed?
thanks
rich

Ofer said:
Try and set the focus to another object in the subform instead of the main form

Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
--
I hope that helped
Good luck


Rich1234 said:
I have a main form "A" with a subform "B." When a button, "lock/unlock" on
form A is pressed, one existing button on subform B is set to invisisble and
two other command buttons are set to visible.
Here is the problem:
After one of these command buttons is pressed, another form "C" opens in a
new window where the user can view or edit data. When the user returns to
the main form and subform "B" by closing form "C", the command button they
used to open form C still has the focus.. so when I click the lock/unlock
button on form A, I get the error, "You can't hide a control that has the
focus."

I know there are a few possible solutions to this one. I want to change the
focus to a textbox, "VRM" on the main form A whenever the lock/unlock button
is pressed. In VB for the lock button onclick event I have tried
Me.VRM.SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")

but it doesn't solve the problem. The Me.VRM.SetFocus doesn't seem to have
any effect (in that the control previously pressed still generates the error.)
What am i doing wrong here? Do I need to put something else before the
Me.VRM.SetFocus? (Is it something to do with the fact that the buttons
hidden are in the subform and the lock button is on the main form?) There are
lots of things that are toggled between visible/invisible when the lock
button is pressed and rather than coding each one individually, I just want
to reset the focus to a textbox on the main form when the lock button is
pressed.

TIA
rich
 
Thanks Ofer. I created an invisisble text box in the subform to temporarily
hold the focus during this process, as none of the controls are guaranteed to
be visible in all circumstances.

rich

Ofer said:
Try this
Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")
Me.VRM.SetFocus

--
I hope that helped
Good luck


Rich1234 said:
Thanks for your suggestion Ofer.
Sometimes, the user wll be amending information in textboxes in the main
form (and not those in the subform) after clicking the ock/unlock button.
Is there a way to simply send forcus to the textbox VRM every time the
lock/unlock button is pressed?
thanks
rich

Ofer said:
Try and set the focus to another object in the subform instead of the main form

Me.Subform_B_Name.Form.[Another Control Name that is visible].SetFocus
--
I hope that helped
Good luck


:

I have a main form "A" with a subform "B." When a button, "lock/unlock" on
form A is pressed, one existing button on subform B is set to invisisble and
two other command buttons are set to visible.
Here is the problem:
After one of these command buttons is pressed, another form "C" opens in a
new window where the user can view or edit data. When the user returns to
the main form and subform "B" by closing form "C", the command button they
used to open form C still has the focus.. so when I click the lock/unlock
button on form A, I get the error, "You can't hide a control that has the
focus."

I know there are a few possible solutions to this one. I want to change the
focus to a textbox, "VRM" on the main form A whenever the lock/unlock button
is pressed. In VB for the lock button onclick event I have tried
Me.VRM.SetFocus
Me.Subform_B_Name.Form.Controls![CommandButton].Visible = IIf(bAllow,
"False", "True")

but it doesn't solve the problem. The Me.VRM.SetFocus doesn't seem to have
any effect (in that the control previously pressed still generates the error.)
What am i doing wrong here? Do I need to put something else before the
Me.VRM.SetFocus? (Is it something to do with the fact that the buttons
hidden are in the subform and the lock button is on the main form?) There are
lots of things that are toggled between visible/invisible when the lock
button is pressed and rather than coding each one individually, I just want
to reset the focus to a textbox on the main form when the lock button is
pressed.

TIA
rich
 
Back
Top