PC Review


Reply
Thread Tools Rate Thread

Conditional Disable ActiveX button on Userform

 
 
Ray
Guest
Posts: n/a
 
      2nd Nov 2009
Hi -

Tried searching for this with no luck .... then again, not sure I was
using the proper search terms either ...

I've got a userform that's used to make weekly entries to a hidden
worksheet ... the userform contains 6 textboxes, a combo-box, an 'Add'
button, and a 'close' button. I'd like to add some code that disables
the 'Add' button until all 7 user-fields have some sort of data in
them -- seems like it should be a 'userform_change' type of procedure,
but I don't see that as an option in the VBE.

Can anyone give an idea how to implement my idea?

TIA,
ray
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Nov 2009
One way...

Option Explicit
Private Sub ComboBox1_Change()
Call CheckInput
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub TextBox1_Change()
Call CheckInput
End Sub
Private Sub TextBox2_Change()
Call CheckInput
End Sub
Private Sub TextBox3_Change()
Call CheckInput
End Sub
Private Sub TextBox4_Change()
Call CheckInput
End Sub
Private Sub TextBox5_Change()
Call CheckInput
End Sub
Private Sub TextBox6_Change()
Call CheckInput
End Sub
Private Sub UserForm_Initialize()

With Me.ComboBox1
.AddItem "a"
.AddItem "B"
.AddItem "C"
End With

With Me.CommandButton1
.Caption = "Ok"
.Default = True
.Enabled = False
End With

With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
.Enabled = True
End With
End Sub
Sub CheckInput()

Dim iCtr As Long
Dim OkToContinue As Boolean

OkToContinue = True
'I used textbox1, ..., textbox6, so I can loop through them
For iCtr = 1 To 6
If Me.Controls("Textbox" & iCtr).Value = "" Then
OkToContinue = False
Exit For 'stop looking
End If
Next iCtr

If Me.ComboBox1.Value = "" Then
OkToContinue = False
End If

Me.CommandButton1.Enabled = OkToContinue

End Sub

If you've named the textboxes differently, you could just check by name:

if TBInput1.value = "" then oktocontinue = false
if TBSSN.value = "" then oktocontinue = false
if TBAmount.value = "" then oktocontinue = false



Ray wrote:
>
> Hi -
>
> Tried searching for this with no luck .... then again, not sure I was
> using the proper search terms either ...
>
> I've got a userform that's used to make weekly entries to a hidden
> worksheet ... the userform contains 6 textboxes, a combo-box, an 'Add'
> button, and a 'close' button. I'd like to add some code that disables
> the 'Add' button until all 7 user-fields have some sort of data in
> them -- seems like it should be a 'userform_change' type of procedure,
> but I don't see that as an option in the VBE.
>
> Can anyone give an idea how to implement my idea?
>
> TIA,
> ray


--

Dave Peterson
 
Reply With Quote
 
Ray
Guest
Posts: n/a
 
      2nd Nov 2009
Perfect Dave ... thanks VERY much!

As an added bonus, I think I can apply this same logic to another
(unrelated) 'problem' I have ... so I' ve learned to 'fish' a bit
better!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable UserForm 'X' Close Button dimm Microsoft Excel Programming 2 25th Mar 2008 03:26 AM
Disable the Close button on a Userform Moh Microsoft Excel Programming 7 14th Dec 2007 05:11 PM
UserForm - Disable the 'x' button Jim Burton Microsoft Excel Programming 11 30th Jun 2007 08:19 PM
Disable Userform button =?Utf-8?B?VHJlZm9y?= Microsoft Excel Programming 13 14th Nov 2005 05:36 PM
disable the x button on a userform john.9.williams@bt.com Microsoft Excel Programming 3 8th Jan 2005 04:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 AM.