0
votes

I have a combo box and several text boxes on a form. When I select a value from the combo box I want it to run a query based on that value and populate the text boxes with the data returned by the query. The query should only return one record and the textboxes correnspond to different columns in that record.

I have this code:

Private Sub cbo_equip_loc_Change()
Dim location As String
Me.cbo_equip_loc.SetFocus
location = DLookup("NAME", "Query1", "position = '" & Me.cbo_equip_loc.SelText & "'")
Me.Text51.SetFocus
Me.Text51.Text = location

End Sub

But I get this error: "This property is read-only and can't be set"

Any ideas?

Solved: Im an idiot.

I had some value in the Control Source from something I was trying to do before. Removed that and it worked!

2

2 Answers

3
votes

There is no need to do this:

Me.Text51.SetFocus
Me.Text51.Text = location

it is true that the text property is only available when the control has the focus, but the value property is available without any focus, or Access VBA is quite happy with just the name of the control:

Me.Text51.Value = location

Or

Me.Text51 = location
1
votes

Textbox Text51 is locked, set property Locked to False.