If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Message to appear if no records found

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Mar 2009
Posts: 4
Message to appear if no records found

Hi All,

I've managed to get a working database, including the count function to display the number of records found, but I just need a message to show up when no records are found.

So what I have is a form with a series of combo boxes which link to a query. Once the values have been filled, the Search button takes the user to another form which displays results.

But what I need is that once the Search button is clicked, if there are no records, a message to appear (could be another form?) to say there are no records and to give the user another go (ie. back to the Search form)

Any help would be greatly appreciated.

Many thanks
Simon
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,786
Try

Code:
If DCount("*", "QueryName") = 0 Then
  Msgbox "No records found"
Else
  DoCmd.OpenForm...
End If
__________________
Paul
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Mar 2009
Posts: 4
Thumbs up Thank you!

Many thanks Paul, that worked a treat!!
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Mar 2009
Posts: 3
could you please explain how and where you put the code into access i have tried many times using a macro, putting into the on load option of the form and i continually keep gettting error messages.

can anyone tell me where i am going wrong?

thanks
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,786
In the situation described in this thread, that code would be behind a command button.
__________________
Paul
Reply With Quote
  #6 (permalink)  
Old
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 12,077
just wondering if an Access form has the similar nodata property to a report, so you could insert your message in the forms on load/open event assuming you are opening a new form each time with your macros.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,786
To my knowledge, no (A2k anyway). Forms have a HasData property, but it can only be read while printing or in print preview, so it doesn't really help in this situation.
__________________
Paul
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Mar 2009
Posts: 4
Access 07 Problem

Hi pbaldy,

The code worked fine in Access 03, but having tried it in 07, it doesn't work. Any ideas why not?

Thanks
Reply With Quote
  #9 (permalink)  
Old
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,786
There's nothing there that wouldn't work in 2007. Is the db in a trusted location so that code runs (or has code been enabled via the option in the toolbar)?
__________________
Paul
Reply With Quote
  #10 (permalink)  
Old
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks...

yeah, got it working now. I think it must have been those stupid security settings on Access that prevent anything working properly!

Thanks once again for your help
Reply With Quote
  #11 (permalink)  
Old
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,786
No problemo; glad we got it sorted out.
__________________
Paul
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On