user1175126
user1175126

Reputation: 179

hiding a control which has focus in ms access 2007

I have a combobox on a form. Clicking on a particular label should hide this combobox. The problem is that if the combobox has focus, clicking on the button which hides this combobox gives error.How can I resolve this runtime error?

Upvotes: 4

Views: 8789

Answers (3)

RSDD
RSDD

Reputation: 13

I know this is an old post, but I recently just ran into a similar issue (and this post was in the first 4 or 5 results). If the control you're trying to disable is the first on the subform, try setting its Tab Index to 1, not 0. As soon as the subform gets the focus, the first control on it does, too. I was trying to set this during a Form_Open event, and this solved it.

Upvotes: 1

ChrisPadgham
ChrisPadgham

Reputation: 870

Rather than setting focus to any particular control, which may cause maintenance issues in the future if the controls on the form change, if you simulate a key press of Tab then focus will move to the next object in the tab order.

SendKeys "{TAB}"
DoEvents
Me.Command4.Visible = False

Note the doevents is necessary to allow the processing of the Tab.

Upvotes: -1

Fionnuala
Fionnuala

Reputation: 91376

Move the focus. If necessary, create a very small control to receive the focus.

Me.SomeControlThatIsNotTheCombobox.SetFocus

Re Comments

Note that this label is not associated with a control.

Private Sub Label1_Click()
   Me.Text1.SetFocus
   Me.Label1.Visible = False
End Sub

Upvotes: 3

Related Questions