ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close button on form (https://www.excelbanter.com/excel-programming/413394-close-button-form.html)

Sandy

Close button on form
 
I have a form which opens when excel opens

If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
frmWelcome.Hide
Else
frmWelcome.Show
End If

On the form there is a close button "CommandButton1". Is it possible to give
this button focus so that the user can use the Enter keyboard key rather
than having to click with the mouse?

Thanks
Sandy



Susan

Close button on form
 
in your userform_initialize sub, put

CommandButton1.setfocus

hth
:)
susan

On Jul 1, 10:57*am, "Sandy" wrote:
I have a form which opens when excel opens

* * If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
* * * * frmWelcome.Hide
* * Else
* * * * frmWelcome.Show
* * End If

On the form there is a close button "CommandButton1". Is it possible to give
this button focus so that the user can use the Enter keyboard key rather
than having to click with the mouse?

Thanks
Sandy



Per Jessen

Close button on form
 
Hi Sandy

If you want CommandButton1 to have focus as the userform is shown, right
click on the userform, select tab order, bring CommandButton1 to the top.

Regards,
Per

"Sandy" skrev i meddelelsen
...
I have a form which opens when excel opens

If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
frmWelcome.Hide
Else
frmWelcome.Show
End If

On the form there is a close button "CommandButton1". Is it possible to
give this button focus so that the user can use the Enter keyboard key
rather than having to click with the mouse?

Thanks
Sandy




Sandy

Close button on form
 
As usual never just one method :-)
Many thanks to you both.
sandy

"Sandy" wrote in message
...
I have a form which opens when excel opens

If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
frmWelcome.Hide
Else
frmWelcome.Show
End If

On the form there is a close button "CommandButton1". Is it possible to
give this button focus so that the user can use the Enter keyboard key
rather than having to click with the mouse?

Thanks
Sandy



Dave Peterson

Close button on form
 
As a user, I'm more used to using the Escape key to do the same as the Cancel
key and the Enter key to the same as the "ok" key.

You can accomplish this in your userform_initialize procedure with code like:

With Me.CommandButton1
.Caption = "Cancel"
.Cancel = True
'.Enabled = True
End With

With Me.CommandButton2
.Caption = "Ok"
.Default = True
'.Enabled = False
End With

If you really want to close the userform by hitting enter, you can use .default
= true on that commandbutton. (only one commandbutton can have those
properties.)



Sandy wrote:

I have a form which opens when excel opens

If Sheets("SearchRoundsData").Range("B2").Value = 1 Then
frmWelcome.Hide
Else
frmWelcome.Show
End If

On the form there is a close button "CommandButton1". Is it possible to give
this button focus so that the user can use the Enter keyboard key rather
than having to click with the mouse?

Thanks
Sandy


--

Dave Peterson


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com