Solved

Trigger message box if nothing is selected

Posted on 2014-09-04
4
211 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

896 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

17 Experts available now in Live!

Get 1:1 Help Now