473,465 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create message box when no records found in access form 2013

13 New Member
In the attached image if I give input in the search criteria form it will bring the result in the query format based on input I key in . Incase if no records found after hitting RUN button how can I bring up the message "Sorry,no records found " instead of showing blank records in query .

when I checked the properties of run button some macro is running behind it . So can we add macro program in addition to that to show our message or do we have to write separate VBA program

Attached Images
File Type: jpg message box.jpg (40.4 KB, 10021 views)
Aug 7 '14 #1
9 13616
twinnyfo
3,653 Recognized Expert Moderator Specialist
ESAKKI,

This will be much easier to do in VBA. You should be able to convert the macro behind that button to VBA code, then modify it, so that when the query returns no records, a MsgBox indicates this.

This should be relatively easy to do, once we see the VBA behind the macro.
Aug 7 '14 #2
zmbd
5,501 Recognized Expert Moderator Expert
So as not to confuse you...
In EXCEL, the term Macro is used for a VBA script.
However, in ACCESS, there are two programing languages.
Access-Macro = Generally used for simple things and web database.

Access-VBA = Used by most of the Access programers here, I highly advise you to learn and use the VBA programing language.

As for your current situation...
You will have to use a conditional and the domain agregate functions
So open your form in design mode.
Insert an if then
insert an else tothe if then
move your open command down to the else
insert a message box into the true section
Use the DCOUNT() in your IF() criteria (hint, you can use a wild card for the expresion and you don't have any criteria)
...

Try this yourself... if you get stuck...
IN ACC2010:
Open the macro in the editor
Click into the editing box
<ctrl><A>
<ctrl><C>
Come back to the postbox here at bytes...
Please, click on the [CODE/] button in the post toolbar and then cut and paste your script between the [code] [/code] tags.

If you would like to do this in VBA - there are basiclly two methods - DCount() or Recordset
<MAKE A BACKUP OF YOUR FILE>
NB:This is a oneway trip for the open form. Once done you can not easily convert from VBA to Macro (yuck :P :d)
Open the form in design mode
In the ribbon, From Design Tools, Design, Tools
"Convert Form's Macros to Visual Basic."
Same section in the Ribbon,
"View Code"
If you haven't named the controls something usefull, then you'll get to hunt for controlnamehere_ONCLICK
You can recycle the VBA code written for you, add yuor IF...THEN consturcts as
Aug 7 '14 #3
ESAKKI109
13 New Member
Can we give me the VBA coding to show the message "No record found " as I don't have much idea how to write VBA coding for my requirement.

Form name in my database: new_orders_search_form
query name in my database:whole_order_track_list qry

the concept is once i keyed in the data in new_orders_search_form it will open up the query named as (whole_order_track_list qry) based on my input . what I have done is if I don't give any input in search form it will bring all the datas which already existed in the query .

because I have written criteria in whole_order_track_list qry that

"Like "*" & [FORMS]![NEWORDERS_SEARCH_FORM]![CUSTOMER_NAME]
& "*" .

So when I give input in new_orders_search_form if the relavant data does not exist in that query then it should pop up the "no record found message" instead of showing blank query .
what is the Vba coding for this case. also let me know where I have to implement the VBA coding . I mean what is the procedure?
Attached Files
File Type: pdf WHOLE HISTORY.pdf (295.0 KB, 392 views)
Aug 8 '14 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Before we go much further you should understand that while we're happy to help you along and fill in any gaps in your knowledge, we are not a free code-writing service. We expect you to learn from the help you get here so that you are in a position to do it for yourself next time a similar issue comes up. Those members who try to use us simply to do their work for them are showing disrespect and will soon become very unpopular. So. Moving on.

I would suggest use of the Current event. It may be necessary (as I struggle to follow your explanations.) to ensure this is only ever done when the form is opened. The code I'll suggest incorporates this logic :
Expand|Select|Wrap|Line Numbers
  1. Private blnNotFirst As Boolean
  2.  
  3. Private Sub Form_Current()
  4.     If blnNotFirst Then Exit Sub
  5.     blnNotFirst = True
  6.     If Not Me.Recordset.EOF Then Exit Sub
  7.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo)
  8. End Sub
bnlNotFirst will start as False by default. Once it's been through the routine the first time it will be set to True so the code will never run again.

Me.NewRecord is another way of testing for there being no data selected but this can be confused by a recordset which is not updatable or otherwise has no new record.
Aug 10 '14 #5
zmbd
5,501 Recognized Expert Moderator Expert
ESAKKI109:
In the same thought as NeoPa; I've sent you a copy of my boilerplate with tutorials and (what I hope) are other resource links. Please check your Bytes.Com inbox. (^_^)
Aug 11 '14 #6
AccessAirForce
1 New Member
Hi there NeoPa,

You seem a bit salty ha ha , been burned I take it :)

Anyhoo, I am adding the same note into my VBA just browsing through to see what you all use. I believe my problem is placement of the code line.

Have a good day
Nov 24 '14 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Not sure I completely follow you, but we do have deal of experience as to how these forums benefit the members the most. The experts are human like us all and very few of us respond well to people treating us without respect.

Of course, the reverse is also true. Many experts here are very easy to take advantage of. Just a little respect and they'll go an extra mile for people.

So simple really, yet we've all had to deal many times with members that don't even get that. Such is life.
Nov 28 '14 #8
aflores41
57 New Member
Expand|Select|Wrap|Line Numbers
  1. If DCount("*", "table name or query") > 0 Then
  2. DoCmd.Close
  3. DoCmd.OpenForm "form name", acNormal, , , acFormReadOnly
  4. Application.SetOption ("auto compact"), 1
  5. Else
  6. Application.SetOption ("auto compact"), 1
  7. MsgBox "No Records To Display"
  8. End If
Dec 3 '14 #9
zmbd
5,501 Recognized Expert Moderator Expert
aflores41:
Better to do this as indicated in post#5 or via record set.
Also I highly recommend not using the "autocompact" as shown on lines 4 and 6 on close... Allen Browne - Bug Report unless you like your databases corrupted.
Dec 4 '14 #10

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
9
by: Frances | last post by:
Hi All, * PREMISE * I'm creating an Access form with 150 items subdivided into 20 categories. Multiple categories (and items) can be selected so my user wants checkboxes. All of the options...
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. ...
1
by: lorirobn | last post by:
Hello, I created an Access database in Access 2002-2003 that I am trying to convert to Access 2000. During conversion, I get error "The report name ' dirDataCopy' you entered in either the...
1
by: nithasha | last post by:
Hi, I need to display a message " NO EMPLOYEES TO REPORT" after the Top Title in a SQLPLUS report when no rows are retrieved by a select statement. So how do i go about? Regards, Nithasha.
1
by: miguelfc | last post by:
Hi, I've searched a lot and couldn't find an answer to my problem. I want to have a field in my form that allow me to paste an image from the clipboard to, for example, a Paint field. Then, I...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
2
LeighW
by: LeighW | last post by:
Hi all, I have a form, Form 1 with primary key PK_ID I have a second form, Form 2 with foreign key FK_ID I link through to Form 2 using the field PK_ID. It is also possible to open Form 2...
1
by: ESAKKI109 | last post by:
In Microsoft access 2013 how can I set last record as a default without VBA coding and macro when form opens?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.