Select Query

  • Thread starter Thread starter John
  • Start date Start date
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
 
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] & "'")
 
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
 
Thanks Guys,
After a bit of modification to fit my database everything works fine

Regards

John
 
Back
Top