Select Query

J

John

Hi
When I run my query from a command button, the query shows the result in the
query window. I do not want this to happen and would like the result shown
in a text box on a form when the command button is clicked.
Can this be accomplished.

Query Name. qryEmail
Form Name. frmEmail
Command Button Name. cmdSelectEmail

Regards

John
 
O

Ofer Cohen

Does the query return only one record?

On the OnClick event you can write the code
Me.[TextFieldNameInForm]=Dlookup("FieldName","qryEmail")

If the query return few records, you need to add a WhereCondition to the
DlookUp
Me.[TextFieldNameInForm]=Dlookup("FieldName","qryEmail","[KeyField] = " &
Me.[KeyFieldInForm])

If the key field that you search by is a text field then change it to

Me.[TextFieldNameInForm]=Dlookup("FieldName","qryEmail","[KeyField] = '" &
Me.[KeyFieldInForm] & "'")
 
J

JethroUK©

if your query produces more than one record - you should replace the command
button with a combo box

place your query statement in the combo box record source

combo will produce the results each time you click it
 
J

John

Thanks Guys,
After a bit of modification to fit my database everything works fine

Regards

John
 
Top