Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Enable / Disable Buttons

Hi

On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to
different sheets however I'm slipping up sometimes by clicking on the wrong
button and sending the info to the wrong sheet is it possible by using a
Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable
CB2 and Disable CB1 and CB3
--
Many Thanks

Sue
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Enable / Disable Buttons

You could use 3 checkboxes to enable/disable each of the 3 commandbuttons--or
you could use 3 optionbuttons and choose the one checkbox that you want enabled.

Or you could just add a prompt to the 3 procedures that do the work:

Dim Resp as long
resp = inputbox(Prompt:="Are you sure you want to use CB1",buttons:=vbyesno)
if resp = vbno then
exit sub
end if

====
But if you want...

I create a small userform with a frame, 3 optionbuttons in that frame and 3
commandbuttons.

The frame was named: Frame1
The Optionbuttons were named: OptionButton1, OptionButton2, OptionButton3
The Commandbuttons were named: Commandbutton1, Commandbutton2, commandbutton3

This was the code I used:

Option Explicit
Private Sub OptionButton1_Click()
Call DoTheWork(WhichOne:=1)
End Sub
Private Sub OptionButton2_Click()
Call DoTheWork(WhichOne:=2)
End Sub
Private Sub OptionButton3_Click()
Call DoTheWork(WhichOne:=3)
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me
For iCtr = 1 To 3
.Controls("Optionbutton" & iCtr).Value = False
.Controls("Commandbutton" & iCtr).Enabled = False
Next iCtr
.Frame1.Caption = "Choose The Commandbutton"
End With
End Sub
Private Sub DoTheWork(WhichOne As Long)
Dim iCtr As Long
For iCtr = 1 To 3
Me.Controls("Commandbutton" & iCtr).Enabled = CBool(iCtr = WhichOne)
Next iCtr
End Sub


Sue wrote:

Hi

On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to
different sheets however I'm slipping up sometimes by clicking on the wrong
button and sending the info to the wrong sheet is it possible by using a
Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable
CB2 and Disable CB1 and CB3
--
Many Thanks

Sue


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Enable / Disable Buttons

Hi Mr Peterson

Thank you for your help I used your Frame Solution to good effect works
really well
--
Many Thanks

Sue


"Dave Peterson" wrote:

You could use 3 checkboxes to enable/disable each of the 3 commandbuttons--or
you could use 3 optionbuttons and choose the one checkbox that you want enabled.

Or you could just add a prompt to the 3 procedures that do the work:

Dim Resp as long
resp = inputbox(Prompt:="Are you sure you want to use CB1",buttons:=vbyesno)
if resp = vbno then
exit sub
end if

====
But if you want...

I create a small userform with a frame, 3 optionbuttons in that frame and 3
commandbuttons.

The frame was named: Frame1
The Optionbuttons were named: OptionButton1, OptionButton2, OptionButton3
The Commandbuttons were named: Commandbutton1, Commandbutton2, commandbutton3

This was the code I used:

Option Explicit
Private Sub OptionButton1_Click()
Call DoTheWork(WhichOne:=1)
End Sub
Private Sub OptionButton2_Click()
Call DoTheWork(WhichOne:=2)
End Sub
Private Sub OptionButton3_Click()
Call DoTheWork(WhichOne:=3)
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me
For iCtr = 1 To 3
.Controls("Optionbutton" & iCtr).Value = False
.Controls("Commandbutton" & iCtr).Enabled = False
Next iCtr
.Frame1.Caption = "Choose The Commandbutton"
End With
End Sub
Private Sub DoTheWork(WhichOne As Long)
Dim iCtr As Long
For iCtr = 1 To 3
Me.Controls("Commandbutton" & iCtr).Enabled = CBool(iCtr = WhichOne)
Next iCtr
End Sub


Sue wrote:

Hi

On a userform I have 3 commandbuttons - say CB1, CB2,CB3 all send info to
different sheets however I'm slipping up sometimes by clicking on the wrong
button and sending the info to the wrong sheet is it possible by using a
Checkbox to use CB1 and Disable CB2 & CB3 and like wise when necessary Enable
CB2 and Disable CB1 and CB3
--
Many Thanks

Sue


--

Dave Peterson

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
Enable/Disable Macro D Excel Programming 2 January 11th 08 04:18 PM
enable/disable multiple buttons Shoney Excel Discussion (Misc queries) 1 January 11th 08 02:41 AM
Enable/Disable CommandBar Buttons Based on Events M. Authement Excel Programming 11 October 19th 06 02:46 AM
Enable/Disable Macro Brandon[_5_] Excel Programming 0 June 1st 04 06:36 PM
macro disable and enable. paul[_12_] Excel Programming 1 January 9th 04 01:29 PM


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

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"