Can't Hide Control that has the focus

NeroMaj

Registered User.
Local time
Today, 15:12
Joined
Sep 13, 2010
Messages
34
I have a set of controls that are made visible upon clicking a button. When a subsequent button is pressed, these controls are made invisible again. This is what I am using right now.

Code:
Private Sub cmdUpdateProfile_Click()
 
  Forms!frmWelcome.setfocus
  tboname.visible = false
  tbophone.visible = false
  tboPassword.visible = false
  tboautologin.visible = false
  cmdUpdateProfile.visible = false
 
End Sub

All of these go invisible, but when I try to set the visibility of the cmdUpdateProfile to False, I get the "You can't hide control that has the focus" error message. I don't understand this, because it no longer has focus.

Note that the cmdUpdateProfile is the button I am clicking as well as the button I am trying to hide...this may be the issue.

Please give me any suggestions as to how to fix this.
 
Try setting the focus to another object/control instead of the form
 
Alright I changed Form_frmwelcome.setfocus to Form_frmWelcome.cmdEditProfile.setfocus and received the same error.

It runs through the set focus line, but its like it returns the focus back to the cmdUpdateProfile after I set it.
 
Set the focus to a control that is on that form, not on another form. See if that helps.
 
Well,that worked. Kind of sucks thats the only solution in this case, because there are no other controls on that form that are visible when trying to make that one invisible, so i just addeda tiny command button in one of the corners that you can't even see and just switched focus to it.
 
You can make the command button's backstyle transparent (with no caption).

If you still want to set focus to the other form, set focus to the button then set it to the form followed by your other code. As long as the button was the last control to get focus on that form, then it wouldn't bomb!
 
I am receiving, I cant hide a control that has a focus.

Private Sub cmdOpen_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.cmdOpen.Visible = True Then
Me.cmdOpen.Visible = False
Me.openGreenBtn.Visible = True
End If
End Sub

Private Sub cmdExit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.cmdExit.Visible = True Then
Me.cmdExit.Visible = False
Me.exitWhiteBtn.Visible = True
End If
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.cmdOpen.Visible = False Then Me.cmdOpen.Visible = True
If Me.cmdExit.Visible = False Then Me.cmdExit.Visible = True
End Sub
 
@TxStrob
This thread is almost 9 years old. Better to start your own thread.
The answer is to set the focus to another visible control then hide the first one
So add a line like Me.SomeOtherControl.SetFocus first
 
Or you could add a little tiny text box in the corner and set the focus to it.
 

Users who are viewing this thread

Back
Top Bottom