Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default SetFocus in a custom dialog

Hi

I have a logon dialog created with two fields (username & password)
and two buttons (login and cancel).

I'm checking with an event if the fields are empty and enable the
login-button only then.

Private Sub txtPwd_AfterUpdate()
If Me.txtUsr.Value < "" And Me.txtPwd.Value < "" Then
Me.cmdLogin.Enabled = True
Me.cmdLogin.SetFocus
Else
Me.cmdLogin.Enabled = False
Me.txtPwd.SetFocus
End If
End Sub

If both fields (Username and Password) are different than "" then I
enable the login-button. And I also want to set the focus on this
login button. But although I do this using the Me.cmdLogin.SetFocus
the focus is set to the next item (the cancel-button). I've tried to
set it on the password-field or any other object, but it just isn't
setting the focus on the login-button.

What am I doing wrong?

Any hint appreciated.

Matthias
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SetFocus in a custom dialog

I would use both textbox_change procedures to decide to enable/disable the login
button. I wouldn't move focus to that button at all.

Option Explicit
Private Sub CommandButton1_Click()
MsgBox "Login was clicked"
Unload Me
End Sub
Private Sub CommandButton2_Click()
MsgBox "Cancel was clicked"
Unload Me
End Sub
Private Sub TextBox1_Change()
Call EnableLoginCheck
End Sub
Private Sub TextBox2_Change()
Call EnableLoginCheck
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Login"
.Default = True
.Enabled = False
.TakeFocusOnClick = False
End With
With Me.CommandButton2
.Caption = "Cancel"
.Cancel = True
.TakeFocusOnClick = False
End With
Me.TextBox1.SetFocus
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call CommandButton2_Click
End If
End Sub
Sub EnableLoginCheck()

Dim Ok As Boolean
Ok = True
If Trim(Me.TextBox1.Value) = "" Then
Ok = False
End If
If Trim(Me.TextBox2.Value) = "" Then
Ok = False
End If

Me.CommandButton1.Enabled = Ok

End Sub


wrote:

Hi

I have a logon dialog created with two fields (username & password)
and two buttons (login and cancel).

I'm checking with an event if the fields are empty and enable the
login-button only then.

Private Sub txtPwd_AfterUpdate()
If Me.txtUsr.Value < "" And Me.txtPwd.Value < "" Then
Me.cmdLogin.Enabled = True
Me.cmdLogin.SetFocus
Else
Me.cmdLogin.Enabled = False
Me.txtPwd.SetFocus
End If
End Sub

If both fields (Username and Password) are different than "" then I
enable the login-button. And I also want to set the focus on this
login button. But although I do this using the Me.cmdLogin.SetFocus
the focus is set to the next item (the cancel-button). I've tried to
set it on the password-field or any other object, but it just isn't
setting the focus on the login-button.

What am I doing wrong?

Any hint appreciated.

Matthias


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default SetFocus in a custom dialog

On 12 Sep., 17:57, Dave Peterson wrote:
I would use both textbox_change procedures to decide to enable/disable the login
button. *I wouldn't move focus to that button at all.

Option Explicit
Private Sub CommandButton1_Click()
* * MsgBox "Login was clicked"
* * Unload Me
End Sub
Private Sub CommandButton2_Click()
* * MsgBox "Cancel was clicked"
* * Unload Me
End Sub
Private Sub TextBox1_Change()
* * Call EnableLoginCheck
End Sub
Private Sub TextBox2_Change()
* * Call EnableLoginCheck
End Sub
Private Sub UserForm_Initialize()
* * With Me.CommandButton1
* * * * .Caption = "Login"
* * * * .Default = True
* * * * .Enabled = False
* * * * .TakeFocusOnClick = False
* * End With
* * With Me.CommandButton2
* * * * .Caption = "Cancel"
* * * * .Cancel = True
* * * * .TakeFocusOnClick = False
* * End With
* * Me.TextBox1.SetFocus
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
* * If CloseMode = vbFormControlMenu Then
* * * * Call CommandButton2_Click
* * End If
End Sub
Sub EnableLoginCheck()

* * Dim Ok As Boolean
* * Ok = True
* * If Trim(Me.TextBox1.Value) = "" Then
* * * * Ok = False
* * End If
* * If Trim(Me.TextBox2.Value) = "" Then
* * * * Ok = False
* * End If

* * Me.CommandButton1.Enabled = Ok

End Sub



wrote:

Hi


I have a logon dialog created with two fields (username & password)
and two buttons (login and cancel).


I'm checking with an event if the fields are empty and enable the
login-button only then.


Private Sub txtPwd_AfterUpdate()
* * If Me.txtUsr.Value < "" And Me.txtPwd.Value < "" Then
* * * *Me.cmdLogin.Enabled = True
* * * *Me.cmdLogin.SetFocus
* * Else
* * * *Me.cmdLogin.Enabled = False
* * * *Me.txtPwd.SetFocus
* * End If
End Sub


If both fields (Username and Password) are different than "" then I
enable the login-button. And I also want to set the focus on this
login button. But although I do this using the Me.cmdLogin.SetFocus
the focus is set to the next item (the cancel-button). I've tried to
set it on the password-field or any other object, but it just isn't
setting the focus on the login-button.


What am I doing wrong?


Any hint appreciated.


Matthias


--

Dave Peterson


Hi Dave

Thanks for your answer.

I've changed it according to your reply, but still, even with no
SetFocus the "cursor" jumps to the cancel button instead of the login
button when I have changed the password-field. If I don't change the
password-field it tabs correctly to the login-button.

Matthias
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SetFocus in a custom dialog

How is the focus jumping to the next control?

Are you hitting enter or tab?

There is a .tabindex property that you can use to make sure the tab/enter takes
you to the correct next control.

And there is a .tabstop property that you can use to skip any of the controls
you want.



wrote:

<<snipped
Hi Dave

Thanks for your answer.

I've changed it according to your reply, but still, even with no
SetFocus the "cursor" jumps to the cancel button instead of the login
button when I have changed the password-field. If I don't change the
password-field it tabs correctly to the login-button.

Matthias


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default SetFocus in a custom dialog

On 12 Sep., 20:55, Dave Peterson wrote:
How is the focus jumping to the next control?

Are you hitting enter or tab?

There is a .tabindex property that you can use to make sure the tab/enter takes
you to the correct next control.

And there is a .tabstop property that you can use to skip any of the controls
you want.


Dave

I'm pressing the tab-key to move out of the password-field and the
focus is then set to the cancel-button.

TabIndex 0 is the label for the username-field with TabStop = False
(so that I can use the accelerator)
TabIndex 1 is the username-field with TabStop = True
TabIndex 2 is the label for the password-field with TabStop = False
(so that I can use the accelerator)
TabIndex 3 is the password-field with TabStop = True
TabIndex 4 is the Login-button with TabStop = True
TabIndex 5 is the Cancel-button with TabStop = True

Matthias


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default SetFocus in a custom dialog

On 12 Sep., 21:40, Dave Peterson wrote:
If you set the tabstop to false, then you're going to skip that control.

But it is NOT set to false. It is TRUE on the login-button.

It is only set to false on the LABELS for the two fields.

Matthias
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SetFocus in a custom dialog

I don't have any more guesses.

I'd double check those .tabindex's, though.

wrote:

On 12 Sep., 21:40, Dave Peterson wrote:
If you set the tabstop to false, then you're going to skip that control.

But it is NOT set to false. It is TRUE on the login-button.

It is only set to false on the LABELS for the two fields.

Matthias


--

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
Display a Custom Dialog Box BHatMJ Excel Discussion (Misc queries) 3 May 21st 08 09:24 AM
Help with Custom Dialog Box nospaminlich Excel Programming 3 January 26th 06 08:52 PM
Custom Dialog Boxes iambalrog[_3_] Excel Programming 1 December 16th 05 10:04 AM
Custom View Dialog Box GLT Excel Discussion (Misc queries) 0 November 13th 05 03:20 PM
Custom made dialog box Deeds[_2_] Excel Programming 1 May 27th 04 07:58 PM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"