View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
AB[_2_] AB[_2_] is offline
external usenet poster
 
Posts: 236
Default Command button - check listbox contents before activating?

Something like this:

Option Explicit

Public Property Get MayProceed() As Boolean

Const MySecretNumber As Long = 7

With Me.ListBox1
If Not .Value = MySecretNumber Or .ListIndex = -1 Then
MayProceed = False
Else
MayProceed = True
End If
End With

End Property


Private Sub CommandButton1_Click()

If Not MayProceed Then
MsgBox "Uups - numbers don't match!!", vbExclamation
Exit Sub
End If

End Sub


On 3 Dec, 17:00, Roger on Excel
wrote:
[Excel 2003]

I have command buttons on the userform which access other userforms (which
drive the spreadsheet data entry)

I have a listbox on the userform displaying a number.

I would like to enter code into the command button activations such that if
the number in the listbox does not equal the *number stored within the code
of the command button then a mesage box is displayed and the command button
does not activate its sub routines.

Can anyone help?

Thanks,

Roger