473,406 Members | 2,745 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,406 software developers and data experts.

No Entries in a Query

102 64KB
Background:
Front End: MS Access 2010/VBA
Back End: MS SQL Server 2008

I have a form called Accounts. Accounts has a sub form that list all Items (sub form name Items example attached). In the example there are no items in the query. How do I display in the query the words "No Items to Display" when there is nothing to display? Thanks.
Attached Files
File Type: docx Doc1.docx (25.0 KB, 264 views)
Apr 7 '15 #1

✓ answered by jforbes

I mocked this up in a test database that was doing something similar. Most of the code was already there, I just added the Label. This code Filters a SubForm of Companies based on what is supplied in a TextBox. I'm guessing what you end up with would be something similar:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdApplyFilter_Click()
  2.     Dim sSearch As String
  3.     sSearch = Nz(Me.txtSearch.Value, "")
  4.     If Len(sSearch) > 0 Then
  5.         Me.CompanySub.Form.Filter = "Company LIKE '*" & sSearch & "*'"
  6.         Me.CompanySub.Form.FilterOn = True
  7.     Else
  8.         Me!CompanySub.Form.FilterOn = False
  9.     End If
  10.  
  11.     Call Form_Current
  12. End Sub
  13. Private Sub Form_Current()
  14.     Dim bSubRecords As Boolean
  15.     bSubRecords = (DCount("CompanyID", "Company", Me.CompanySub.Form.Filter) <> 0)
  16.     Me.CompanySub.Visible = bSubRecords
  17.     Me.lblNoRecords.Visible = Not bSubRecords
  18. End Sub
Maybe, instead of Me.CompanySub.Form.Filter for the Criteria, it would be something like: "idAcounts=" & Me.frmIDAccounts.Value

3 960
jforbes
1,107 Expert 1GB
Hey sc5502,

I would create a Label that says "No Items to Display" as the Caption. I would make it the same size at the SubForm and place it in the same place on the Form as the SubForm.

Then in the OnCurrent Event of the Form I would perform a DCount on the Table that the SubForm is based on with the same criteria of the SubForm. If the Count is 0 make the New Label Visible and make the SubReport non-visible, if the Count is greater than 0, make the SubReport visible and the Label non-visible. (You can also create a Clone of the SubForms recordset to find out the Record Count... up to you.)
Apr 8 '15 #2
sc5502
102 64KB
How do I code your example when the form/sub form is set up like in the attached?
Attached Files
File Type: docx Doc2.docx (37.9 KB, 321 views)
Apr 8 '15 #3
jforbes
1,107 Expert 1GB
I mocked this up in a test database that was doing something similar. Most of the code was already there, I just added the Label. This code Filters a SubForm of Companies based on what is supplied in a TextBox. I'm guessing what you end up with would be something similar:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdApplyFilter_Click()
  2.     Dim sSearch As String
  3.     sSearch = Nz(Me.txtSearch.Value, "")
  4.     If Len(sSearch) > 0 Then
  5.         Me.CompanySub.Form.Filter = "Company LIKE '*" & sSearch & "*'"
  6.         Me.CompanySub.Form.FilterOn = True
  7.     Else
  8.         Me!CompanySub.Form.FilterOn = False
  9.     End If
  10.  
  11.     Call Form_Current
  12. End Sub
  13. Private Sub Form_Current()
  14.     Dim bSubRecords As Boolean
  15.     bSubRecords = (DCount("CompanyID", "Company", Me.CompanySub.Form.Filter) <> 0)
  16.     Me.CompanySub.Visible = bSubRecords
  17.     Me.lblNoRecords.Visible = Not bSubRecords
  18. End Sub
Maybe, instead of Me.CompanySub.Form.Filter for the Criteria, it would be something like: "idAcounts=" & Me.frmIDAccounts.Value
Apr 8 '15 #4

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

Similar topics

4
by: Bacci | last post by:
I have two tables. The first is "Locations" which has 52,000 zip codes w/cooresponding latitudes and longitudes. The second "Suppliers" has 2,000 company names and addresses. The user enters a...
15
by: GTi | last post by:
I have a query like: SELECT "ProjectMembers"."RoleText", "ProjectMembers"."Description", "ContactTable"."Name1", "ContactTable"."Name2", "ContactTable1"."Name1", "ContactTable1"."Name2" FROM...
10
by: nick_faye | last post by:
Hi guys, i'm still a newbie in using MS Access and in VB programming. I am using DAO connection from my VB to access the entries on my MS Access table. I am having trouble in editting and...
1
by: Robert | last post by:
I am trying to create a db for service providers by county. I'm relatively new to db programming, but I have done quite a bit of programming ranging from the old basic days up to doing some...
1
by: Astra | last post by:
Hi All Strange request I know, but could somebody give me pointers on how I can put 3 queries into 1 'thing' and then get only the unique entries from this 'thing'. To explain, I'm using...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
0
by: xadrian | last post by:
Hi, I'm trying to put together a query that will order entries in a table by the rating values which decay over time. I'm not too well versed in the intricacies of Postgres, or complex queries,...
5
by: bpbull | last post by:
SQL Server 2003 - SQL Query Analyzer. We have a database that stores service tickets and a table called non_part_usage. In this table, we have one field called request_id, one field called...
1
by: fformulaa | last post by:
Can't figure out how to sum up a total of hours from same date entries. Query: SELECT work_hrs_for_day.empl_numbr, work_hrs_for_day.user_date, work_hrs_for_day.workday_totl,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.