Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to eliminate and error for user entry...

Status
Not open for further replies.

kalebson

Programmer
Mar 3, 2006
60
US
I am using a list box for our scheduling database in which the "Days Off" are selected for an employee. What happens is if for some reason nothing is selected you get an error saying:

"Invalid call or procedure"

What I would like to do is have a msgbox pop up if nothing is selected so the person knows that they forgot to select the days off without them having to wonder what the "Invalid call or procedure" error is. this is what im using:

Private Sub Command51_Click()
On Error GoTo Err_Command51_Click

Dim stDocName As String
Dim ctl As Control
Dim varItm As Variant
Dim myStr As String
Dim strSQL As String

Set ctl = DaysOffSelect

For Each varItm In ctl.ItemsSelected
myStr = myStr & ctl.ItemData(varItm) & ","
ctl.Selected(varItm) = False
Next varItm
myStr = Left(myStr, Len(myStr) - 1)
Me.DaysOffSelect = myStr

I tried adding something like :

If IsNull(varItm) Then MsgBox ("You must enter the employee's days off to save this record.")

but it didnt pop up before the error.. any ideas? TIA
 
Put in something like:

Code:
If Me.DaysOffSelect.ItemsSelected.Count = 0 Then
    MsgBox "Nothing selected"
    'Exit Sub
Else
    'Do stuff
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top