Solved

Trigger message box if nothing is selected

Posted on 2014-09-04
4
215 Views
Last Modified: 2014-09-04
This should be simple, but I haven't been able to figure it out.

I have a multi select list box. I want to give the user an error message if they click a button and nothing is selected. this is what I have right now:

If IsNull(Me!lstPrevRpts) Then
MsgBox "No Previous Activity Has Been Selected"
Me!lstPrevRpts.SetFocus

End If

Open in new window


Now I get the message box, but I get it even when items are selected. So that part about "If IsNull...." doesn't seem to be doing anything.

I am sure this is probably something simple that I just don't know how to do. I have tried several other ways of coding this, but nothing seems to be working for me.
0
Comment
Question by:Megin
  • 2
4 Comments
 
LVL 16

Expert Comment

by:13598
ID: 40304385
try this:
if (string.IsNullOrEmpty(Me!lstPrevRpts.SelectedText))
MsgBox "No Previous Activity Has Been Selected"
Me!lstPrevRpts.SetFocus

End If
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 40304388
Check the ItemsSelected.Count property:

If Me.YourListBox.ItemsSelected.Count = 0 Then
  'user did not select anything
Else
  ' user selected at least one
End If
0
 
LVL 84
ID: 40304392
if (string.IsNullOrEmpty(Me!lstPrevRpts.SelectedText))
That's .NET code, not VBA. It won't work in Access.
0
 

Author Closing Comment

by:Megin
ID: 40304409
Works great!

I don't know what I would do without the experts here! Thank you!!!!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unable to save new report from old one 9 25
Can not open the Access Help ? 3 52
sql statement - 9 23
Access Crosstab Query with Multiple Values 4 31
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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

813 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

10 Experts available now in Live!

Get 1:1 Help Now