PDA

View Full Version : Ghost button until valid entry



lclisby
09-04-2015, 01:48 PM
Hello,
My program asks for an input (probably using an input box, but maybe something else would work better for this), and I want to make the Okay button ghosted out and unclickable until the entry is the right length of characters.

I know I could just pop up a box that says "Wrong length" and return them to the entry box, but that's not as sleek as I'd like.
Is there a way to do this?

Thanks!

Paul_Hossler
09-04-2015, 05:02 PM
You can do that with a user form




Option Explicit

Private Sub butCancel_Click()
Me.Hide
Unload Me
End Sub

Private Sub butOK_Click()
MsgBox "That's 8 characters"
Me.Hide
Unload Me
End Sub

Private Sub tbEntry_Change()
With Me
.labCounter.Caption = Len(.tbEntry.Text)
If .labCounter.Caption = "8" Then
.butOK.Enabled = True
Else
.butOK.Enabled = False
End If
End With
End Sub

Private Sub UserForm_Initialize()
With Me
.butOK.Enabled = False
.labCounter.Caption = "0"
End With
End Sub

lclisby
09-04-2015, 08:33 PM
Thanks Paul!

I think by looking up tutorials on user forms I can figure out the details.

Paul_Hossler
09-05-2015, 07:49 AM
OK

Ask any questions

UFs are nice and flexible for things like this, plus you can add all the polish and eye candy you want (pictures, logos, frames, options, command button caption changes, etc.)