Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2006, 05:38 PM
mmm mmm is offline
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Disable CommandButton in Userform

Hi all

I am making a user form which have 3 text boxes, OK and CANCEL buttons. I want to disable the OK button until all the textboxes filled. Once all textbox fields are filled with input data, the OK button becomes enabled.

I woner how can I do this. I tried various ideas but could not do it. Could you help please.

Thanks;

 
Old November 20th, 2006, 03:30 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

First thing to do is set OK commandbutton property Enabled=False

Write your code something like this:

Private Sub TextBox1_Change()
If TextBox1 = True And TextBox2 = True And TextBox3 = True Then
    CommandButton1.Enabled = True
Else
    CommandButton1.Enabled = False
End If
End Sub

Private Sub TextBox2_Change()
Call TextBox1_Change
End Sub

Private Sub TextBox3_Change()
Call TextBox1_Change
End Sub

-vemaju
 
Old November 20th, 2006, 06:41 AM
mmm mmm is offline
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

vemaju

I tried this way previously but didn't work. I applied it with your suggestion again but didn't work either. I don't know where lies the error!!

Anyone can help please.

Thanks to all.

 
Old November 20th, 2006, 06:44 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Can you post the code?

-vemaju
 
Old November 20th, 2006, 06:52 AM
mmm mmm is offline
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added another two textboxes but I think it would be the same , as follows:

Private Sub txtMW_Change()
    Call txtName_Change
End Sub

Private Sub txtName_Change()
    If txtName = True And txtMW = True And txtSG = True And txtTc = True And txtParachor = True Then
        cmdOK.Enabled = True
    Else
        cmdOK.Enabled = False
    End If
End Sub

Private Sub txtParachor_Change()
    Call txtName_Change
End Sub

Private Sub txtSG_Change()
    Call txtName_Change
End Sub

Private Sub txtTc_Change()
    Call txtName_Change
End Sub




 
Old November 20th, 2006, 07:11 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

This code works well in my Userform.
Try to insert breakpoin in your code and inspect where the error lies

-vemaju
 
Old November 20th, 2006, 07:49 AM
mmm mmm is offline
Registered User
 
Join Date: Nov 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried the following, it worked fine:

If Not txtName = "" And Not txtMW = "" And Not txtSG = "" And Not txtTc = "" And Not txtParachor = "" Then
    cmdOK.Enabled = True
Else
    cmdOK.Enabled = False
End If

It seems the "TextBox1 = True" does not work, at least with me.

Anyway, vemaju thanks for the help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
CommandButton to display directory mona_upm84 Excel VBA 2 September 25th, 2008 09:21 PM
How to apply Khmer Unicode to CommandButton Chieng Sisovin VB.NET 2002/2003 Basics 3 September 12th, 2007 03:09 AM
Help! CommandButton Caption Driving Me Nuts! phoenixblue C# 0 September 29th, 2006 03:19 AM
CommandButton & OnAction or HyperlinkType virtualboy Excel VBA 0 October 17th, 2004 03:48 PM
Toolbar CommandButton Kenny Alligood Beginning VB 6 1 September 30th, 2004 06:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.