Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Focus In Modeless Form (spare me the grief)


I hope someone out there can help me.
I have a modeless Form. It has 1 label and one textbox.
on exit of the textbox(by user hitting enter) It looses it focus t
Excel. However When I give focus back to the userform b
AppActivate(userform1.caption) Textbox1 has the focus, However ther
is no cursor indication and I can not overwrite what is currently i
the field, it only appears to allow me to backspace over the previou
entry. Here is the code I am using :

Module 1 -- code:
Sub ShowUserForm()
If UserForm1.Visible = True Then
AppActivate (UserForm1.Caption)
Else
UserForm1.Show (vbModeless)
End If
End Sub

UserForm1 -- code:
Private Sub TextBox1_Enter()
Me.TextBox1.BackColor = &HFFFF&
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
Me.TextBox1.BackColor = &H80000005
AppActivate ("Microsoft excel")
End Sub

Private Sub UserForm_Activate()
Me.TextBox1.SetFocus
End Sub

*** note Ive had a little bit of success with the userform_click even
and adding a second text box, But I dont want the user to click on th
body of the userform to set the focus.

PLEASE PLEASE HELP!!

--
ThinkImInTroublePosted from http://www.pcreview.co.uk/ newsgroup acces

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Focus In Modeless Form (spare me the grief)

Hi,

Control's focus is effective only in its container object.
Even if a userform loses focus, active-control keeps focus
while its container(userform) is alive, so 2nd 'enter' is not raised.

I might have misunderstood what you mean, but made some code:

'exsample-1 (Excel 2000)
'assuming that UserForm1 has a commandbutton.

'Standard module
Sub ShowUserForm()
If UserForm1.Visible Then
UserForm1.Show vbModeless
UserForm1.Tag = "ResetFocus"
UserForm1.CommandButton1.SetFocus
UserForm1.Tag = ""
UserForm1.TextBox1.SetFocus
Else
UserForm1.Show vbModeless
UserForm1.TextBox1.SetFocus
End If
End Sub

'UserForm1
Private Sub TextBox1_Enter()
Me.TextBox1.BackColor = &HFFFF&
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.Tag = "" Then
Cancel = True
Me.TextBox1.BackColor = &H80000005
AppActivate Application.Caption
End If
End Sub


'exsample-2

'Standard module
Sub ShowUserForm()
UserForm1.Show vbModeless
With UserForm1.TextBox1
.BackColor = &HFFFF&
.Visible = False
.Visible = True
.SetFocus
End With
End Sub

'UserForm1
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
Me.TextBox1.BackColor = &H80000005
AppActivate Application.Caption
End Sub

--
HTH,
okaizawa

ThinkImInTrouble wrote:
I hope someone out there can help me.
I have a modeless Form. It has 1 label and one textbox.
on exit of the textbox(by user hitting enter) It looses it focus to
Excel. However When I give focus back to the userform by
AppActivate(userform1.caption) Textbox1 has the focus, However there
is no cursor indication and I can not overwrite what is currently in
the field, it only appears to allow me to backspace over the previous
entry. Here is the code I am using :

Module 1 -- code:
Sub ShowUserForm()
If UserForm1.Visible = True Then
AppActivate (UserForm1.Caption)
Else
UserForm1.Show (vbModeless)
End If
End Sub

UserForm1 -- code:
Private Sub TextBox1_Enter()
Me.TextBox1.BackColor = &HFFFF&
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = True
Me.TextBox1.BackColor = &H80000005
AppActivate ("Microsoft excel")
End Sub

Private Sub UserForm_Activate()
Me.TextBox1.SetFocus
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Focus In Modeless Form (spare me the grief)


Thanks okaizawa, I had a feeling it was due to the control keeping it
focus. I just wasnt sure how to code it to reinitiliaze The Textbo
control. I Love The second example you gave.

Thank you again you saved me Many Sleepless nights

--
ThinkImInTroublePosted from http://www.pcreview.co.uk/ newsgroup acces

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
How do I switch focus from a modeless user form back to the excel. Yoam69 Excel Programming 7 December 7th 04 07:26 PM
Modeless User Form and Worksheet Focus JWolf Excel Programming 2 May 26th 04 08:27 PM
Removing focus from a Modeless Form? Ian Chappel Excel Programming 2 May 1st 04 07:54 PM
Modeless but waiting form Zdenek Moravec Excel Programming 7 January 14th 04 02:00 PM
Focus back from modeless userform to sheet RB Smissaert Excel Programming 4 September 5th 03 04:21 PM


All times are GMT +1. The time now is 12:28 AM.

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

About Us

"It's about Microsoft Excel"