Solved

Trigger message box if nothing is selected

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default value of combobox 25 69
vb.net dbnull syntax 1 53
Combo box question 6 53
Ranking Students in Ms Access based on given Criteria 5 58
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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