PC Review


Reply
Thread Tools Rate Thread

Button Focus

 
 
Sandy
Guest
Posts: n/a
 
      3rd Jul 2009
Excel 2003
I have a button from the Forms toolbar named "Register".
The button is on the sheet - not on a form.

I would like to set the focus to this button in the following code

Code>>
Sub Worksheet_Change(ByVal Target As Range)

If Range("A1").Value <> "" Then
Buttons("Register").SetFocus
Else
........... other code..........
End if

End Sub
<<Code

Obviously this does not work - it produces the following error:-

"Run-Time error '438':
Object doesn't support this property or method"

Any help appreciated

Sandy
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      3rd Jul 2009

Controls from the Forms menu do not have a SetFocus method. You could use
'Select' but I suspect you don't want to do that. You may want to change to
an ActiveX button, simply call the original code from its click event in the
worksheet module. You'll then be able to do -

ActiveSheet.OLEObjects("CommandButton1").Activate

Regards,
Peter T

"Sandy" <(E-Mail Removed)> wrote in message
news:802ABD16-C7D7-4CB0-96E7-(E-Mail Removed)...
> Excel 2003
> I have a button from the Forms toolbar named "Register".
> The button is on the sheet - not on a form.
>
> I would like to set the focus to this button in the following code
>
> Code>>
> Sub Worksheet_Change(ByVal Target As Range)
>
> If Range("A1").Value <> "" Then
> Buttons("Register").SetFocus
> Else
> ........... other code..........
> End if
>
> End Sub
> <<Code
>
> Obviously this does not work - it produces the following error:-
>
> "Run-Time error '438':
> Object doesn't support this property or method"
>
> Any help appreciated
>
> Sandy



 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      3rd Jul 2009

Option Explicit

Sub Worksheet_Change(ByVal Target As Range)

If Range("A1").Value <> "" Then
''Buttons("Register").SetFocus
ActiveSheet.Shapes("Register").Select
Else
'........... other code..........
End If

End Sub





"Sandy" <(E-Mail Removed)> wrote in message
news:802ABD16-C7D7-4CB0-96E7-(E-Mail Removed)...
> Excel 2003
> I have a button from the Forms toolbar named "Register".
> The button is on the sheet - not on a form.
>
> I would like to set the focus to this button in the following code
>
> Code>>
> Sub Worksheet_Change(ByVal Target As Range)
>
> If Range("A1").Value <> "" Then
> Buttons("Register").SetFocus
> Else
> ........... other code..........
> End if
>
> End Sub
> <<Code
>
> Obviously this does not work - it produces the following error:-
>
> "Run-Time error '438':
> Object doesn't support this property or method"
>
> Any help appreciated
>
> Sandy


 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      3rd Jul 2009
Whats the point of selecting the button? Why don't you just trigger some
code with an input box ? I assume that you're "asking" the user to do
something?

"Sandy" <(E-Mail Removed)> wrote in message
news:802ABD16-C7D7-4CB0-96E7-(E-Mail Removed)...
> Excel 2003
> I have a button from the Forms toolbar named "Register".
> The button is on the sheet - not on a form.
>
> I would like to set the focus to this button in the following code
>
> Code>>
> Sub Worksheet_Change(ByVal Target As Range)
>
> If Range("A1").Value <> "" Then
> Buttons("Register").SetFocus
> Else
> ........... other code..........
> End if
>
> End Sub
> <<Code
>
> Obviously this does not work - it produces the following error:-
>
> "Run-Time error '438':
> Object doesn't support this property or method"
>
> Any help appreciated
>
> Sandy


 
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
>> button has focus Jonathan Microsoft Access Form Coding 4 23rd Sep 2009 07:03 PM
Set Focus on Button =?Utf-8?B?R2lkaQ==?= Microsoft C# .NET 0 31st Dec 2005 07:29 PM
Button Focus =?Utf-8?B?RGFyY3k=?= Microsoft Dot NET Compact Framework 6 10th Apr 2005 01:39 PM
How to set focus on a button ? =?Utf-8?B?RGFuaWVs?= Microsoft ASP .NET 1 26th Apr 2004 03:01 PM
Button focus Mike Microsoft C# .NET 5 27th Nov 2003 08:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:42 PM.