No records returned by query

  • Thread starter Kenneth H. Young
  • Start date
K

Kenneth H. Young

I have a form with a query for a data source that returns mismatched data.

SELECT Arpwatch.IP, Arpwatch.Name, Arpwatch.[Mac Address], Arpwatch.[Last
Seen]
FROM Arpwatch LEFT JOIN [DHCP List] ON Arpwatch.IP = [DHCP List].[Client IP
Address]
WHERE ((([DHCP List].[Client IP Address]) Is Null));

When no records are returned the form opens and displays a blank page. I
have tried applying an 'On Load' event that if 'IP' is null to display a
msgbox that there is no data to display and then close the form. I have also
tried If Not IsNull then ... Else msgbox and then close. Nether of these
work. How can I handle this if no records are returned by the query?

Thank you for any assistance

Ken
 
C

Cheryl Fischer

See if the following code, in the form's Open event, will work for you:

If Me.RecordsetClone.Recordcount = 0 then
Msgbox "There is no data to display."
Cancel = True
End If


hth,
 
K

Kenneth H. Young

Thanks I'll give it a try.


Cheryl Fischer said:
See if the following code, in the form's Open event, will work for you:

If Me.RecordsetClone.Recordcount = 0 then
Msgbox "There is no data to display."
Cancel = True
End If


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Kenneth H. Young said:
I have a form with a query for a data source that returns mismatched data.

SELECT Arpwatch.IP, Arpwatch.Name, Arpwatch.[Mac Address], Arpwatch.[Last
Seen]
FROM Arpwatch LEFT JOIN [DHCP List] ON Arpwatch.IP = [DHCP List].[Client IP
Address]
WHERE ((([DHCP List].[Client IP Address]) Is Null));

When no records are returned the form opens and displays a blank page. I
have tried applying an 'On Load' event that if 'IP' is null to display a
msgbox that there is no data to display and then close the form. I have also
tried If Not IsNull then ... Else msgbox and then close. Nether of these
work. How can I handle this if no records are returned by the query?

Thank you for any assistance

Ken
 
Y

Yuan Shao

Hello Ken,

I noticed that the issue was posted twice in this news group
(microsoft.public.access.formscoding). I have added the response from the
old post below:

From Marsh:

Check the form for no records like this:

If Me.RecordsetClone.RecordCount > 0 Then
' Do whatever when there is data
Else
MsgBox "No unmatched records"
DoCmd.Close acForm, Me.Name, acSaveNo
End If

--
Marsh
MVP [MS Access]

////////////////////////////

From Jeff:

Ken

Is your form set to "AllowAdditions"? For "DataEntry"?

--
Good luck

Jeff Boyce
<Access MVP>

//////////////////////////////


How is the issue going on you side now? Did you fix your problem? If you
have follow up questions on this issue, please post in the latest thread
and we will work with you. Thanks.

Regards,

Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top