Solved

Trigger message box if nothing is selected

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now