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

Populating text box with the results of a query 2

Status
Not open for further replies.

Gerbers404

Programmer
Jun 11, 2001
84
US
Hi there. I would like to be able to run a select query (which will return only one record of one field) and transfer the results of that query to a field on a form... Is there any way that this can be done? Basically, I have a combo box wich allows user to select an employee. I want to have a field on the form that automatically displays that person's e-mail address (the name and e-mail address reside in the same table) that I can reference to as the "To:" part of the send object command. Seems that the only way I can do this is to query by name and return the address to that field, but I don't understand how to put the address into the field. It also doesn't seem like it would automate very well. Maybe my logic is lacking. Are there any ideas?

Thanks,

Gerbers404
 

In the "After Update" event of the combo box use the DLookUp function to set the value of the text box.

The code would look something like the following.

Private Sub Combo1_AfterUpdate()
Me.Textbox2 = DLookUp("[EmailAddress]","TableName","[Name]='" & Me.Combo1 & "'")
End Sub Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Hey Terry, It worked great, thank you! I don't understand what the use of the ' means. I typed in the code just like you said, by what is "[Name]='" & Me.Combo1 & "'") saying? Just for my info if you have a chance.... If not, your help was still very appreciated! Thanks again.

Gerbers404

 
Terry's use of ', actually "'", is way of inserting a single quote inside of a string surrounded by double quotes. If you used double quotes, the program would get confused and attempt to end the string; therefore, you must use single quotes inside of double quotes. Terry's routine was an excellent response to your need and I'm going to give him an Atta-boy for it, too.

mac
 
how would the expression change if the name and email address were kept in seperate tables?
 

Nazgul79,

Do the tables have an esablished relationship? Or do you have a way to tie the name to an Email address? That info is vital to knowing how to write the query expression. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top