When Query reutrns no results.

  • Thread starter Thread starter hotrod1952 via AccessMonster.com
  • Start date Start date
H

hotrod1952 via AccessMonster.com

Newbie:
I have the following code for a query:

PARAMETERS [Enter Task Number] Text;
SELECT Task.TaskID, WODef.WODefID
FROM (Task INNER JOIN WODefTask ON Task.TaskNo = WODefTask.TaskNo) INNER JOIN
WODef ON WODefTask.WODefNo = WODef.WODefNo
WHERE (((Task.TaskID)=[Enter Task Number]))
ORDER BY Task.TaskID;

I am using a command button on a form to run this query. What I would like is
a msgbox to pop-up stating no results when the query returns no results.
Should that be done in the form or in the query?
 
Newbie:
I have the following code for a query:

PARAMETERS [Enter Task Number] Text;
SELECT Task.TaskID, WODef.WODefID
FROM (Task INNER JOIN WODefTask ON Task.TaskNo = WODefTask.TaskNo) INNER JOIN
WODef ON WODefTask.WODefNo = WODef.WODefNo
WHERE (((Task.TaskID)=[Enter Task Number]))
ORDER BY Task.TaskID;

I am using a command button on a form to run this query. What I would like is
a msgbox to pop-up stating no results when the query returns no results.
Should that be done in the form or in the query?

You can't do this in the query itself.
However, if you display the query result on a form bound to this
query, you can.

Create a new form, using the query as it's record source.
Code the Form's Open event:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records to display"
Cancel = true
End If

Then use the command button on the form you currently have to open the
new form (instead of opening the query):
DoCmd.OpenForm "FormName"

If there is no data in the query, the message will appear. The form
will not open.
 
Back
Top