Solved

Trigger message box if nothing is selected

Posted on 2014-09-04
4
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85

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 85
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: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

705 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