Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Conditional Disable ActiveX button on Userform

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Conditional Disable ActiveX button on Userform

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Conditional Disable ActiveX button on Userform

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
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
how to disable/enable command button(ActiveX) using macro enahs_naneek Excel Discussion (Misc queries) 1 February 5th 10 12:32 PM
UserForm - Disable the 'x' button Jim Burton Excel Programming 11 June 30th 07 08:19 PM
Disable Exit button on a UserForm Noemi Excel Discussion (Misc queries) 1 September 14th 06 09:37 PM
Disable Userform button Trefor Excel Programming 11 November 14th 05 04:04 PM
disable the x button on a userform [email protected] Excel Programming 3 January 8th 05 04:29 PM


All times are GMT +1. The time now is 11:50 PM.

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

About Us

"It's about Microsoft Excel"