Solved

Access Listbox - Empty/Null

Posted on 2013-01-07
11
505 Views
Last Modified: 2013-01-08
Hello All

I have a Tabbed Form with a Subform on one of the Tab's .  On that Subform I have a Listbox to display info about a Contact.  It works fine to display existing info.  However, if the List is Null is there a way for essentially a message to appear within that Listbox of say "-{None}-" or  "-{No Info}-"
0
Comment
Question by:wlwebb
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 38750191
What is the rowsource for the listbox?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38750193
No... a workaround is to place a label or textbox above it and in whatever event is controlling the listbox rowsouce:

If me.lstBox.rowcount = 0 then
     Me.txtBox = "No Records"
Else
       Me.txtbox = "total records: " & me.lstbox.rowcount
End if
0
 

Author Comment

by:wlwebb
ID: 38750196
Peter
Me.listShipperLocations.RowSource = "SELECT ShipperLocID, ShipperLoc, ShipperID FROM dta_ShippersLocations" & _
    " WHERE (((ShipperID)=[Forms]![tfrm_Shippers]![sfrm_dta_ShippersLocations].[Form]![ShipperID]))" & _
    " ORDER BY ShipperLoc"

Mbiz.....
That's sort of what I thought ......

I'll see if Peter has a different approach
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38750210
I think Miriam's solution is fine.
I was going to look at counting records but Miriam's approach is simpler.
0
 

Author Comment

by:wlwebb
ID: 38750211
I tried a couple If stmts

    If Me.listShipperLocations.ListCount = 0 Then
        Me.listShipperLocations.RowSource = "{No Locations}-"
    End If
    Me.listShipperLocations.Requery


    If Me.listShipperLocations.ListCount = 0 Then
        Me.listShipperLocations.Value = "{No Locations}-"
    End If
    Me.listShipperLocations.Requery

But none worked.........
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 61

Expert Comment

by:mbizup
ID: 38750257
You can't set the listbox like that.  The idea is to use a textbox above the listbox to display the listcount or "no records".
0
 
LVL 30

Expert Comment

by:hnasr
ID: 38750408
Interesting request! I'll give it a try.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38750422
Not sure if you have a .Net background... but gridviews, etc in .Net DO have this option, allowing you to specify text to display if there are no records present.  It appears as non-selectable text centered in the gridview.

Access listboxes do not have this option.  You can possibly set the row source to display "No Records", but unlike .Net, in Access it would be an actual list item -- which would be selectable unless you include code to lock/disable the listbox for such cases.  Also, if your listbox has multiple colomns, the text would have to appear in one of the columns rather than centered across the listbox.

The easiest way IMO to inform the user is to use a seperate textbox (or text boxes) to display the number of items in the list as described above.

Our standard for that here is to use two textboxes with associated labels to show how many 'filtered' records the listbox is displaying and the total possible number of unfiltered records - something like this:

          Displaying X  of  Y total records

Where X is the listcount of filtered records, and Y is the total number of unfiltered records.  (We place this information/textboxes immediately under the right hand corner of the listbox)
0
 
LVL 30

Expert Comment

by:hnasr
ID: 38750461
Try this:
Replace with your table, and field names.

Table 0 (f1, f2, f3) - this is your table to display contents of listbox  if any.
Table a(....) used to display {x} - if table 0 is empty.

Select Distinct "", " {x}" ,"" 
From a Where Not Exists(SELECT [0].[f1], [0].[f2],[0].[f2] FROM 0)
UNION 
SELECT [0].[f1], [0].[f2],[0].[f2] 
FROM 0 ;

Open in new window

0
 

Author Closing Comment

by:wlwebb
ID: 38754777
Thanks Mbiz.....
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38754808
Glad to help out :-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Autocomplete textbox in MS Access 2016 4 23
How calculate median 5 38
Recording mileage on a form 2 11
Syntax using Declare 3 11
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now