473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA code for "No records found" in search

Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the corresponding records based on a query i have built in to the code below which is applied to the search command button in my search form.

Private Sub Command4_Click()
DoCmd.OpenForm "frmriskass", acNormal, "qrysearchriskass", , acFormReadOnly
Me.Area = ""
End Sub

It works fine when there is a matching record, but the problem i have is when there is no corresponding record. All i get is a blank form whith no fields or command buttons on it.

How do i change the code so that if there are no corresponding records i will get a message box which says something like "No corresponding record, please search again" and instead of a blank form being opened i can click Ok and go back to my original search form to try again?
Apr 23 '07 #1
11 6740
Sorry. Just realised i had code as acFormReadOnly but have changed this to acFormEdit so i can still input in to the appropriate records found, however if there is no corresponding record i know just get an empty form ready to be completed. Still need code so this doesn't happen.

Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the corresponding records based on a query i have built in to the code below which is applied to the search command button in my search form.

Private Sub Command4_Click()
DoCmd.OpenForm "frmriskass", acNormal, "qrysearchriskass", , acFormReadOnly
Me.Area = ""
End Sub

It works fine when there is a matching record, but the problem i have is when there is no corresponding record. All i get is a blank form whith no fields or command buttons on it.

How do i change the code so that if there are no corresponding records i will get a message box which says something like "No corresponding record, please search again" and instead of a blank form being opened i can click Ok and go back to my original search form to try again?
Apr 23 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Can you post the sql for the filter.
Apr 24 '07 #3
The sql i have for this filter is below:

SELECT tblRiskAss.ReferenceNumber, tblRiskAss.RiskAssessorsName, tblRiskAss.[Hospice Premesis], tblRiskAss.Area, tblRiskAss.Date, tblRiskAss.[Hazard Group Name], tblRiskAss.[State Problem and Risk], tblRiskAss.[Risk Level], tblRiskAss.[Action Taken], tblRiskAss.[Management Status], tblRiskAss.[Person at Risk], tblRiskAss.[Risk Communicated To], tblRiskAss.[Assessment Review Period], tblRiskAss.[Frequency of Monitoring], tblRiskAss.AssessmentReviewDate, tblRiskAss.[Last Reviewed], tblRiskAss.NextReviewDate, tblRiskAss.Completed, tblRiskAss.ysnSentByMailToStaff
FROM tblRiskAss
WHERE (((tblRiskAss.RiskAssessorsName)=[Forms]![frmsearchriskass]![RiskAssessorsName]) AND ((tblRiskAss.Area)=[Forms]![frmsearchriskass]![Area]));

It filters for matching [Risk Assessors Name] and [Area].

Just not sure why it still brings up a blank form ready for data input if no matches for this filter or if there are matches you get the matching record plus a blank one to complete if you scroll with the mouse wheel.

Hope you can help.

Thanks
Apr 24 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
For the mousewheel problem try this ...

http://www.lebans.com/mousewheelonoff.htm

This will disable the mousewheel
Apr 25 '07 #5
Thanks for that. It will come in handy in other parts of my database.

I can't apply it to this as my search may find more than one record so being able to scroll is useful.

I just can't get my head around why the code with the filter i have either turns up all matching records plus one blank record or if there are no matches for the filters i have used to search for then all i get is a blank record.

Any ideas?
Apr 25 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
Thanks for that. It will come in handy in other parts of my database.

I can't apply it to this as my search may find more than one record so being able to scroll is useful.

I just can't get my head around why the code with the filter i have either turns up all matching records plus one blank record or if there are no matches for the filters i have used to search for then all i get is a blank record.

Any ideas?
Set the forms Allow Additions property to No
Apr 25 '07 #7
Thanks. I tried this but it doesn't make any difference. Grrrh! I still get the corresponding records displayed as the forms when i run the code but with addition of this one blank form ready for data entry. Or if there are no matches, just one blank form, ready for data entry.

Thanks for any more help you can give with this. Is it my code? or is it my filter?
Apr 25 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
Thanks. I tried this but it doesn't make any difference. Grrrh! I still get the corresponding records displayed as the forms when i run the code but with addition of this one blank form ready for data entry. Or if there are no matches, just one blank form, ready for data entry.

Thanks for any more help you can give with this. Is it my code? or is it my filter?
Honestly don't know why this is happening
Apr 25 '07 #9
I am a bit lost with it also. Thanks for all the bits of advice though. I suppose i can't solve every problem i encounter.

Thanks again
Apr 26 '07 #10
Lysander
344 Expert 100+
I am a bit lost with it also. Thanks for all the bits of advice though. I suppose i can't solve every problem i encounter.

Thanks again
Just tried this, and I think it solves your problem. Set your form to not allow additions and then put the following in the onopen event of your form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim rs As Recordset
  3. Set rs = Me.RecordsetClone
  4. If rs.RecordCount = 0 Then
  5.     MsgBox "No Data, Try again"
  6.     DoCmd.Close
  7. End If
  8. End Sub
  9.  
Apr 26 '07 #11
Thanks for this. I have given it a try but no luck.

Thanks anyway
Apr 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim Little | last post by:
In Visual Studio 2003 I was getting a "No files were found to look in" error while doing searches that included the entire solution, a file mask of "*.*" and some text with no special checkboxes...
2
by: amywolfie | last post by:
I would like to place a Find button on a form which uses the built-in Access Find facility. If no records are found, I would like to display a custom "no records found - plesae try again" message...
4
by: amywolfie | last post by:
I would like to put code behind a Find button on a form which: 1) Performs a find based on a field on the form 2) If NO RECORDS ARE FOUND, then displays a custom "No Records Found" message box. ...
5
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right...
1
by: Kim | last post by:
How can I display "No data found" in the repeater if there are no records found after selecting an item from a dropdown list. Another question is: Can repeater perform paging as in datagrid if...
6
by: webonomic | last post by:
"The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty." I get the error above. It tells me the error is in Line 120: ...
1
by: scottmachado | last post by:
I am currently running a marco that run a query and emails the results as an attachment in excel format. If the query has no records, I would like to email "no records found" in the first cell in...
3
by: martin | last post by:
Hello, Could someone here please explain the reason for the error in the subject (the full error below) I dont get this everytime and i've never gotten while debugging. The code (also below)...
1
by: RN1 | last post by:
Sub Page_Load(........) If Not Page.IsPostBack Then Call LoadData() End If End Sub Sub LoadData() Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.