Can't Hide Control that has the focus (1 Viewer)

NeroMaj

Registered User.
Local time
Today, 01:07
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.
 

namliam

The Mailman - AWF VIP
Local time
Today, 08:07
Joined
Aug 11, 2003
Messages
11,695
Try setting the focus to another object/control instead of the form
 

NeroMaj

Registered User.
Local time
Today, 01:07
Joined
Sep 13, 2010
Messages
34
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.
 

vbaInet

AWF VIP
Local time
Today, 07:07
Joined
Jan 22, 2010
Messages
26,374
Set the focus to a control that is on that form, not on another form. See if that helps.
 

NeroMaj

Registered User.
Local time
Today, 01:07
Joined
Sep 13, 2010
Messages
34
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.
 

vbaInet

AWF VIP
Local time
Today, 07:07
Joined
Jan 22, 2010
Messages
26,374
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!
 

TxStrob

Registered User.
Local time
Yesterday, 23:07
Joined
Sep 23, 2019
Messages
44
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
 

isladogs

MVP / VIP
Local time
Today, 07:07
Joined
Jan 14, 2017
Messages
18,218
@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
 

GinaWhipp

AWF VIP
Local time
Today, 02:07
Joined
Jun 21, 2011
Messages
5,899
Or you could add a little tiny text box in the corner and set the focus to it.
 

Users who are viewing this thread

Top Bottom