CommandButton sometimes causes an unspecified error

ernief

New Member
Joined
Dec 9, 2017
Messages
8
Hi
This is my first question.
I have a command button (SaveChangesBtn) that I wish to set focus to under certain circumstances. On many occasions the button works fine, but occasionally I get an unspecified run time error.
It is at the following point in the code

POpenIssuesRowID = r.Row - 1
Call GotoRecord(recordfound, POpenIssuesRowID)
SaveChangesBtn.Enabled = True
SaveChangesBtn.SetFocus

I have stepped through on numerous occasions but cannot see why it should set focus sometimes and not others, Any thoughts please
Regards
ernief
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I use Excel 2007,
there is no control property such as CommandButton1.SetFocus only CommandButton1.TakeFocus*******.
I think SetFocus only available in Visual Basic 6 Command Button.
 
Upvote 0
I use Excel 2007,
there is no control property such as CommandButton1.SetFocus only CommandButton1.TakeFocus*******.
I think SetFocus only available in Visual Basic 6 Command Button.

I am using Excel 2016. I am surprised by your answer. when entering code and using Ctrl+space and start entering the name of the object (CommandButton) "SaveChangesBtn" followed by a full stop "." SetFocus is one of the events in the list. Perhaps this changed from 2007?
 
Upvote 0
Have you tried using SaveChangesBtn.Activate instead of SetFocus ?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top