views:

38

answers:

2

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!

+1  A: 

Textbox Text51 is locked, set property Locked to False.

hgulyan
Actually that property is set to Locked = No. But, im an idiot, I had some value in the Control Source from something I was trying to do before. Removed that and it worked!
kralco626
+3  A: 

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
Remou
I did Me.Text51.Value = location and it gave me an error saying I could not set the value property. Although that may have been before I removed what I had from the Control Source field.
kralco626
@kralco626 I think you will find that it was before you made the change.
Remou
haha yup. Thanks! +1
kralco626