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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text box value from SQL statement 1

Status
Not open for further replies.

denright

Programmer
Oct 19, 2001
7
0
0
I have a form that is bound to a table called ContactHistory. For new records, I would like to populate a text box (txtPersonID) on the form using a query that takes data from another table (Person).

I tried this:

sqlPersonID = "SELECT DISTINCTROW PERSON.PersonID " & _
"FROM PERSON " & _
"WHERE PERSON.First & "" "" & PERSON.Last = cboClientName.Value;"
txtPersonID = sqlPersonID

The query itself works but I can't populate the textbox because txtPersonID is a long and sqlPersonID is a string.

How can I get the value of that query into the text box?

 
Try txtPersonID = CLng(sqlPersonID). BTW, how come txtPersonID is a long datatype? "txt" is the common prefix for text fields.
 
If you print sqlPersonID to the Debug window you will see it looks like this

SELECT DISTINCTROW PERSON.PersonID FROM PERSON WHERE PERSON.First & " " & PERSON.Last = Paul Bricker
Thats what sqlPersonID is being set to, not just the value Paul Bricker.
To do what you want, you will need to use the DLookUp() Function or actually open a recordset based on sqlPersonID. I think the DLookUp would be easier.
Set the control source for txtPersonID to
=DLookUp("PersonID","Person","[First]& ' ' & [Last] = '" & cboClientName & "'")

You may need to adjust the syntax for the Where arugument. I don't know how the data in cboClientName is set up. If it's in two columns your syntax will be different.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top