Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 17th, 2004, 09:04 PM
Spawn1973 Spawn1973 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 Spawn1973 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Query shows no results

Right, I have a form that runs off of a query. The query has a user specified criteria.
If the criteria is not found, the form shows up blank. Is it possible to have textbox appear
that says "No records found matching the search criteria".

Spawn

Reply With Quote
  #2  
Old October 17th, 2004, 10:39 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 10
I would use a simple command to count the records, if no records exist then display a message box. DCount("*",qryName) to count the records. Then your message box in the Open Event of your form if not already open. If the form is already open use it on the AfterUpdate event of the control that opens the query. Set the message box to cancel the event if no records are found. There are other ways, but this is the easiest one I can think of.

Dim iCount as integer

iCount = DCount("*", qryName)

If iCount = 0 Then
If Msgbox("No records found matching the search criteria")=vbOk Then
Cancel=-1
End If
End If
lwells

Reply With Quote
  #3  
Old November 17th, 2004, 08:12 AM
Octopussy Octopussy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 Octopussy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by lwells
I would use a simple command to count the records, if no records exist then display a message box. DCount("*",qryName) to count the records. Then your message box in the Open Event of your form if not already open. If the form is already open use it on the AfterUpdate event of the control that opens the query. Set the message box to cancel the event if no records are found. There are other ways, but this is the easiest one I can think of.

Dim iCount as integer

iCount = DCount("*", qryName)

If iCount = 0 Then
If Msgbox("No records found matching the search criteria")=vbOk Then
Cancel=-1
End If
End If
lwells
-------------------------------------------------------------------------------------------------------------------------------
As the query my form was based on uses a parameter DCount didn't work (it works fine if I run a query without parameter).
The next code does work for me :

Private Sub Form_Open(Cancel As Integer) <-- the OnOpen event in the Form-properties
If Me.Recordset.RecordCount < 1 Then
If MsgBox("No records found matching the search criteria") = vbOK Then
Cancel = -1
End If
End If
End Sub

Serge

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Query shows no results


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap