Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to fix #NAME? in my control source for text box 1

Status
Not open for further replies.

miscluce

MIS
Oct 4, 2007
149
US
I am trying to populate a textbox with a Price from a table based on selection in combo box but this only works with a combo box. can someone help me with this? Thanks in advance

This works:
Private Sub cboModel_AfterUpdate()
Me.cboPrice.RowSource = "SELECT fldPrice FROM tblCar WHERE fldModel = '" & Me.cboModel & "'"
End Sub

This don't: ( I get a #NAME? )
Private Sub cboModel_AfterUpdate()
Me.txtPrice.ControlSource = "SELECT fldPrice FROM tblCar WHERE fldModel = '" & Me.cboModel & "'"
End Sub
 
The control source for a text box is the field that the control is bound to or a function for a calculated control. A sql statement can net be used. Use dlookup for this. Do you actually want to set the control source or just display the value.
Either way use a dlookup. Something like
Me.txtPrice = dlookup ("fldPrice","tblCar", "fldModel = '" & Me.cboModel & "'")

If you want to set the control source that will get a little tricky with your quotations, because you have to pass the whole thing as a string.
Me.txtPrice.controlsource = " = dlookup ('fldPrice','tblCar', 'fldModel = and no idea how to handle the rest ...'"
 
thanks for the info. I still get a #NAME?

I am using this:

Private Sub cboModel_AfterUpdate()

Me.txtPrice.ControlSource = DLookup("fldPrice", "tblCar", "fldModel='" & Me.cboModel & "'")

End Sub

I tried a couple of other ways but no luck. Anybody has ideas?
 
I solved this like this:
Private Sub cboModel_AfterUpdate()

Me.txtPrice = DLookup("fldPrice", "tblCar", "fldModel='" & Me.cboModel & "'")

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top