0

I have two subform (subfrmA and subfrmB)and a main form frmAB. Both subforms are invisible until the user selects what form they want from comboboxAB on the main form. So if user selects Form A in the main form comboboxAB, subfrmA will become visible while subfrmB remains invisible. Then user inputs changes saves and exits.

But when the form is opened back up, I want the forms of the saved records to automatically load so I wrote the below code.

 Private Sub Form_Load () If Me.comboboxAB.Text = “Form A” Then Me.subfrmA.Visible = True Me.subfrmB.Visible = False Me.subfrmA.SourceObject = “Form.Form A” ElseIf Me.comboboxAB.Text = “Form B” Then Me.subfrmB.Visible = True Me.subfrmA.Visible = False Me.subfrmB.SourceObject = “Form.Form B” End If End Sub 

However, I get an error. “Run-time error ‘2185’: You can’t reference a property or method for a control unless the control has the focus.”

And the code:

 If Me.comboboxAB.Text = “Form A” Then 

Is highlighted does anyone know why this is? Also I typed the code up on my tablet, so the quotes in my code look like smart quotes but they are not.

1

1 Answer 1

1

Try using .Value instead of .Text , if i remember correctly the .Text property is only available when focused (which is what that errormessage hints at).

That is to say, you could use .Text in Subs that relate to the Combobox itself being changed, but not within your Form_Load Sub, as that one relates to the Form and not the Combobox itself.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.