473,434 Members | 1,507 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,434 software developers and data experts.

Display Message if No Data Exist through Query / Form

I have created a form, which has 'Query' datasource.

I want a message if query does not show any record, as occured in report of 'On No Data'
Aug 25 '07 #1
2 13016
missinglinq
3,532 Expert 2GB
Use DCount() to check for records returned by query:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim Msg As String
  3. Dim intX As Integer
  4.  
  5. intX = DCount("[PrimaryKeyField]", "YourQueryName")
  6. If intX < 1 Then
  7. Msg = "No Records are Returned by the Query"
  8. MsgBox Msg, vbOKOnly + vbInformation
  9. DoCmd.Close acForm, "YourFormName"
  10. End If
  11. End Sub
  12.  
Linq ;0)>
Aug 25 '07 #2
Jim Doherty
897 Expert 512MB
I have created a form, which has 'Query' datasource.

I want a message if query does not show any record, as occured in report of 'On No Data'
Not sure whether you want it for form or report so heres both

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. On Error Resume Next
  3.     If Me.RecordsetClone.RecordCount = 0 Then
  4.     MsgBox "No records to support form display", vbExclamation, "System Message"
  5.     DoCmd.CancelEvent
  6.     Exit Sub
  7.     End If
  8. Exit Sub
and one for the reports on nodata event

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_NoData(Cancel As Integer)
  2. On Error Resume Next
  3.     Cancel = True
  4. MsgBox "No records to support report", vbExclamation, "System Message"
  5. End Sub
Aug 25 '07 #3

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

Similar topics

3
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
9
by: cooldv | last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this code: message = Replace(usermessage, "'", "''"). My problem is DISPLAYING data in an asp FORM, from an an access database,...
7
by: Matt | last post by:
In ASP, when we pass data between pages, we usually pass by query string. If we pass data by query string, that means we need to use submit button, not by regular button, and the form will pass to...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
1
imrosie
by: imrosie | last post by:
Hello All, I have a combo box that selects a customer and brings up all of the data associated with that customer (Billing data (on Main form), Order data (on Sub form #1) and Shipping Data on Sub...
3
by: beemomo | last post by:
I have two tables - 'Client' and 'Company', and two forms, 'Client' and 'Company', the relationship between two table is 1:many where a company can have one or more client but each of the client...
1
by: mary mathews | last post by:
Hi, I have an access database with Arabic Data. I want to display that data in ASP form(Classis ASP) but it shows only reverse question marks. i have tried with tahoma font in the form,its not...
2
by: smugcool | last post by:
hi, I am very much unaware of working in vb. I have an access database, along with various queries. I wanted to build a form where i can display data of tables,queries in the form. I dont know how...
1
by: rhonda2010 | last post by:
I have a program in which I want to have the user enter two percentages and display the data matching the criteria on a new form. The query would be: Select * From Corrosion Where corrpct1 >=...
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.