Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Command button - check listbox contents before activating?

[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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Command button - check listbox contents before activating?

Hi,

Thanks for the code. Would you know how to make it work if the listbox
contents are a text string?

Roger

"AB" wrote:

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


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Command button - check listbox contents before activating?

Hi,

if the only difference is comparing strings instead of comparing
numbers then technically the only change in the code necessary would
be to dim the constant with a different type (string instead of Long)
like this:

replace this:
Const MySecretNumber As Long = 7

with this
Const MySecretNumber As String = "7"

Obviously the "7" can be anything you need (like "Seven" or "Apple"
or ...)

Post back if i misunderstood the question or didn't answer it.



On Dec 4, 12:40*am, Roger on Excel
wrote:
Hi,

Thanks for the code. *Would you know how to make it work if the listbox
contents are a text string?

Roger



"AB" wrote:
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


.- Hide quoted text -


- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
activating a command button chuck Excel Discussion (Misc queries) 1 September 10th 09 03:12 AM
Activating a command button with a single key stroke Bishop Excel Programming 8 June 3rd 09 07:21 PM
Multiselect Listbox/ command button C Wilson Excel Programming 2 May 21st 07 09:50 PM
Check box making a command button work Rmagic Excel Programming 3 November 12th 05 12:41 AM
printing using vba; listbox/command button bkey01[_4_] Excel Programming 2 April 21st 04 05:54 AM


All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"