PC Review


Reply
Thread Tools Rate Thread

Disabling a forms 1.0 button

 
 
=?Utf-8?B?V2lsbCBGaW5rbGU=?=
Guest
Posts: n/a
 
      30th Sep 2007
Hi,

On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
buttons to run macros, instead of using CommandButtons from the Controls
toolbar -- a decision I am now regretting. . . Anyway, I am using the
following code to temporarily disable buttons created from the Forms toolbar:

Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False

and this does disable the button from calling its OnAction macro. But the
button still appears the same, i.e. the text is not greyed out, and when you
move the mouse over the button, the pointer icon still turns into the "hand".
It is confusing to users, so I would like to make the button's appearance
reflect its current state.

Is there a way to modify the appearance or behavior for this type of button,
other than changing its Visible property to False?

Thank you kindly,


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5hbnQgQmFzYW50?=
Guest
Posts: n/a
 
      30th Sep 2007
Hi Will,

I also faced a similar problem in one of my projects and I applied the
following idea. Since the button can't be grayed out (or if it can I don't
know), I changed the caption of the macro to something like disabled and
changed the OnAction property to a macro that provides a friendly message.
When I wanted to change the button to an Enabled state from some other code,
I called "CallMyButton" macro with a TRUE switch.

I am providing the code below. Hope that solves your problem to some extent.

Option Explicit

Sub CallMyButton()
EnableMyButton True
End Sub

Sub EnableMyButton(bEnabled As Boolean)
Dim btn As Button
Set btn = Sheets("Sheet1").Buttons("Button 4")
If bEnabled Then
With btn
.Caption = "Enabled"
.OnAction = "HelloWorld"
End With
Else
With btn
.Caption = "Disabled"
.OnAction = "DisableButton"
End With
End If
End Sub

Sub HelloWorld()
MsgBox "Hello World"
End Sub

Sub DisableButton()
MsgBox "Sorry!!! You can't run the macro."
End Sub

--
Anant


"Will Finkle" wrote:

> Hi,
>
> On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
> buttons to run macros, instead of using CommandButtons from the Controls
> toolbar -- a decision I am now regretting. . . Anyway, I am using the
> following code to temporarily disable buttons created from the Forms toolbar:
>
> Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False
>
> and this does disable the button from calling its OnAction macro. But the
> button still appears the same, i.e. the text is not greyed out, and when you
> move the mouse over the button, the pointer icon still turns into the "hand".
> It is confusing to users, so I would like to make the button's appearance
> reflect its current state.
>
> Is there a way to modify the appearance or behavior for this type of button,
> other than changing its Visible property to False?
>
> Thank you kindly,
>
>

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      30th Sep 2007
What about hiding the button after you disable it?

Sheet1.Shapes.Item(strButton).OLEFormat.Object.Visible = msoFalse

msoTrue unhides it.

Regards,

OssieMac



"Will Finkle" wrote:

> Hi,
>
> On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
> buttons to run macros, instead of using CommandButtons from the Controls
> toolbar -- a decision I am now regretting. . . Anyway, I am using the
> following code to temporarily disable buttons created from the Forms toolbar:
>
> Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False
>
> and this does disable the button from calling its OnAction macro. But the
> button still appears the same, i.e. the text is not greyed out, and when you
> move the mouse over the button, the pointer icon still turns into the "hand".
> It is confusing to users, so I would like to make the button's appearance
> reflect its current state.
>
> Is there a way to modify the appearance or behavior for this type of button,
> other than changing its Visible property to False?
>
> Thank you kindly,
>
>

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      30th Sep 2007
Hi Will,

I had problems posting this the first time so there is a possibility you
will get it twice.

What about hiding the button after disabling it?

Sheet1.Shapes.Item(strButton).OLEFormat.Object.Visible = msoFalse

of course msoTrue unhides it.

Regards,

OssieMac

"Will Finkle" wrote:

> Hi,
>
> On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
> buttons to run macros, instead of using CommandButtons from the Controls
> toolbar -- a decision I am now regretting. . . Anyway, I am using the
> following code to temporarily disable buttons created from the Forms toolbar:
>
> Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False
>
> and this does disable the button from calling its OnAction macro. But the
> button still appears the same, i.e. the text is not greyed out, and when you
> move the mouse over the button, the pointer icon still turns into the "hand".
> It is confusing to users, so I would like to make the button's appearance
> reflect its current state.
>
> Is there a way to modify the appearance or behavior for this type of button,
> other than changing its Visible property to False?
>
> Thank you kindly,
>
>

 
Reply With Quote
 
=?Utf-8?B?V2lsbCBGaW5rbGU=?=
Guest
Posts: n/a
 
      30th Sep 2007
Hi, Anant,

Thank you, this is very helpful indeed, and although it is definitely a good
solution and reasonable, my UI has 8 buttons that get enabled in 2's & 3's,
and it seems maybe unnecessary -- though I am going to get some feedback from
users tomorrow, and then I can decide whether or not this is necessary. I
just don't like the idea of having to insert 4 constant strings for each
button (2 captions, 2 OnActions...) but there are worse things in life! :-)

By the way, does anyone have an opinion on which buttons seem to be easier
to work with? It seems like these were really easy to initially assign to a
macro, with almost no overhead (i.e. no event handling) but the downside
seems to be the limited UI-configuration options. Any thoughts one way or
another?

thanks 1,000,000,

"Anant Basant" wrote:

> Hi Will,
>
> I also faced a similar problem in one of my projects and I applied the
> following idea. Since the button can't be grayed out (or if it can I don't
> know), I changed the caption of the macro to something like disabled and
> changed the OnAction property to a macro that provides a friendly message.
> When I wanted to change the button to an Enabled state from some other code,
> I called "CallMyButton" macro with a TRUE switch.
>
> I am providing the code below. Hope that solves your problem to some extent.
>
> Option Explicit
>
> Sub CallMyButton()
> EnableMyButton True
> End Sub
>
> Sub EnableMyButton(bEnabled As Boolean)
> Dim btn As Button
> Set btn = Sheets("Sheet1").Buttons("Button 4")
> If bEnabled Then
> With btn
> .Caption = "Enabled"
> .OnAction = "HelloWorld"
> End With
> Else
> With btn
> .Caption = "Disabled"
> .OnAction = "DisableButton"
> End With
> End If
> End Sub
>
> Sub HelloWorld()
> MsgBox "Hello World"
> End Sub
>
> Sub DisableButton()
> MsgBox "Sorry!!! You can't run the macro."
> End Sub
>
> --
> Anant
>
>
> "Will Finkle" wrote:
>
> > Hi,
> >
> > On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
> > buttons to run macros, instead of using CommandButtons from the Controls
> > toolbar -- a decision I am now regretting. . . Anyway, I am using the
> > following code to temporarily disable buttons created from the Forms toolbar:
> >
> > Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False
> >
> > and this does disable the button from calling its OnAction macro. But the
> > button still appears the same, i.e. the text is not greyed out, and when you
> > move the mouse over the button, the pointer icon still turns into the "hand".
> > It is confusing to users, so I would like to make the button's appearance
> > reflect its current state.
> >
> > Is there a way to modify the appearance or behavior for this type of button,
> > other than changing its Visible property to False?
> >
> > Thank you kindly,
> >
> >

 
Reply With Quote
 
=?Utf-8?B?V2lsbCBGaW5rbGU=?=
Guest
Posts: n/a
 
      30th Sep 2007
Hi, OssieMac,

Thank you for the suggestion. I had noticed the visible property, but I
think that would look in my UI, if the buttons were not visible... although,
since they get enabled as the user performs Step1, then Step2, etc... it
might not be so bad. . . I'll check it out.

Thanks again,

"OssieMac" wrote:

> Hi Will,
>
> I had problems posting this the first time so there is a possibility you
> will get it twice.
>
> What about hiding the button after disabling it?
>
> Sheet1.Shapes.Item(strButton).OLEFormat.Object.Visible = msoFalse
>
> of course msoTrue unhides it.
>
> Regards,
>
> OssieMac
>
> "Will Finkle" wrote:
>
> > Hi,
> >
> > On recommendation from a textbook I was reading, I used Forms 1.0 toolbar
> > buttons to run macros, instead of using CommandButtons from the Controls
> > toolbar -- a decision I am now regretting. . . Anyway, I am using the
> > following code to temporarily disable buttons created from the Forms toolbar:
> >
> > Sheet1.Shapes.Item(strButton).OLEFormat.Object.Enabled = False
> >
> > and this does disable the button from calling its OnAction macro. But the
> > button still appears the same, i.e. the text is not greyed out, and when you
> > move the mouse over the button, the pointer icon still turns into the "hand".
> > It is confusing to users, so I would like to make the button's appearance
> > reflect its current state.
> >
> > Is there a way to modify the appearance or behavior for this type of button,
> > other than changing its Visible property to False?
> >
> > Thank you kindly,
> >
> >

 
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
Disabling New Records on Forms in VB John Ortt Microsoft Access Forms 5 14th Mar 2007 03:26 PM
Disabling sub forms =?Utf-8?B?c2N1YmFkaXZlcg==?= Microsoft Access Forms 1 19th May 2006 10:49 AM
What is the reason for disabling the min./max. button in order to make the 'help button' works?! babylon Microsoft Dot NET Framework Forms 2 6th May 2004 07:07 AM
Disabling a Button? =?Utf-8?B?TXIgQg==?= Microsoft Excel Programming 8 30th Mar 2004 10:43 PM
Disabling Forms Redrawing =?Utf-8?B?bWV2YXI=?= Microsoft Dot NET Framework Forms 5 24th Feb 2004 04:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 AM.