PC Review


Reply
Thread Tools Rate Thread

How do you SETFOCUS on TextBox

 
 
Mike
Guest
Posts: n/a
 
      11th Dec 2006
I have two MODELESS UserForms and I need to have the Textbox1 come up with
the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is LOADED
(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE it
(Button2) and then reactivate it (Button1), the focus is gone. I can't seem
to find and way of getting the focus back AUTOMATICALLY after the first
Activation.

IN USERFORM1:
Private Sub CommandButton1_Click()
Userform2.Show
Userform2.Top = 300 'just to offset it from UserForm1
End Sub

Private Sub CommandButton2_Click()
Userform2.Hide
End Sub





 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      11th Dec 2006
Forgot to say that TextBox1 is in UserForm2.

Mike

"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have two MODELESS UserForms and I need to have the Textbox1 come up with
>the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
>Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is LOADED
>(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE it
>(Button2) and then reactivate it (Button1), the focus is gone. I can't seem
>to find and way of getting the focus back AUTOMATICALLY after the first
>Activation.
>
> IN USERFORM1:
> Private Sub CommandButton1_Click()
> Userform2.Show
> Userform2.Top = 300 'just to offset it from UserForm1
> End Sub
>
> Private Sub CommandButton2_Click()
> Userform2.Hide
> End Sub
>
>
>
>
>



 
Reply With Quote
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      11th Dec 2006
Try using setfocus in the userform_activate on userform2

Private Sub UserForm_Activate()
Me.TextBox1.SetFocus

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Mike" wrote:

> Forgot to say that TextBox1 is in UserForm2.
>
> Mike
>
> "Mike" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I have two MODELESS UserForms and I need to have the Textbox1 come up with
> >the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is LOADED
> >(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE it
> >(Button2) and then reactivate it (Button1), the focus is gone. I can't seem
> >to find and way of getting the focus back AUTOMATICALLY after the first
> >Activation.
> >
> > IN USERFORM1:
> > Private Sub CommandButton1_Click()
> > Userform2.Show
> > Userform2.Top = 300 'just to offset it from UserForm1
> > End Sub
> >
> > Private Sub CommandButton2_Click()
> > Userform2.Hide
> > End Sub
> >
> >
> >
> >
> >

>
>
>

 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      11th Dec 2006
Thanks Martin, but that doesn't seem to work.

mike
"Martin Fishlock" <(E-Mail Removed)> wrote in message
news:1DD5ABD6-5E98-4585-8213-(E-Mail Removed)...
> Try using setfocus in the userform_activate on userform2
>
> Private Sub UserForm_Activate()
> Me.TextBox1.SetFocus
>
> End Sub
>
> --
> Hope this helps
> Martin Fishlock
> Please do not forget to rate this reply.
>
>
> "Mike" wrote:
>
>> Forgot to say that TextBox1 is in UserForm2.
>>
>> Mike
>>
>> "Mike" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I have two MODELESS UserForms and I need to have the Textbox1 come up
>> >with
>> >the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
>> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is
>> >LOADED
>> >(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE
>> >it
>> >(Button2) and then reactivate it (Button1), the focus is gone. I can't
>> >seem
>> >to find and way of getting the focus back AUTOMATICALLY after the first
>> >Activation.
>> >
>> > IN USERFORM1:
>> > Private Sub CommandButton1_Click()
>> > Userform2.Show
>> > Userform2.Top = 300 'just to offset it from UserForm1
>> > End Sub
>> >
>> > Private Sub CommandButton2_Click()
>> > Userform2.Hide
>> > End Sub
>> >
>> >
>> >
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
Mark Ivey
Guest
Posts: n/a
 
      11th Dec 2006
Mike,

Just gave it a quick once over and all worked fine for me (see my code
below). Can you give more detail on what problems you are having?

'My code for UserForm1:
'**********************************
Private Sub CommandButton1_Click()
UserForm2.Show
End Sub

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

'My code for UserForm2:
'**********************************
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub

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


"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks Martin, but that doesn't seem to work.
>
> mike
> "Martin Fishlock" <(E-Mail Removed)> wrote in message
> news:1DD5ABD6-5E98-4585-8213-(E-Mail Removed)...
>> Try using setfocus in the userform_activate on userform2
>>
>> Private Sub UserForm_Activate()
>> Me.TextBox1.SetFocus
>>
>> End Sub
>>
>> --
>> Hope this helps
>> Martin Fishlock
>> Please do not forget to rate this reply.
>>
>>
>> "Mike" wrote:
>>
>>> Forgot to say that TextBox1 is in UserForm2.
>>>
>>> Mike
>>>
>>> "Mike" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>> >I have two MODELESS UserForms and I need to have the Textbox1 come up
>>> >with
>>> >the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
>>> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is
>>> >LOADED
>>> >(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE
>>> >it
>>> >(Button2) and then reactivate it (Button1), the focus is gone. I can't
>>> >seem
>>> >to find and way of getting the focus back AUTOMATICALLY after the first
>>> >Activation.
>>> >
>>> > IN USERFORM1:
>>> > Private Sub CommandButton1_Click()
>>> > Userform2.Show
>>> > Userform2.Top = 300 'just to offset it from UserForm1
>>> > End Sub
>>> >
>>> > Private Sub CommandButton2_Click()
>>> > Userform2.Hide
>>> > End Sub
>>> >
>>> >
>>> >
>>> >
>>> >
>>>
>>>
>>>

>
>



 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      11th Dec 2006
Mark,
Your code below doesn't have any HIDE and your buttons are NOT
both in one form. Just copy the code I have below and put all of it in
Userform1 Module. The textbox1 should be in UserForm2.

mike

"Mark Ivey" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Mike,
>
> Just gave it a quick once over and all worked fine for me (see my code
> below). Can you give more detail on what problems you are having?
>
> 'My code for UserForm1:
> '**********************************
> Private Sub CommandButton1_Click()
> UserForm2.Show
> End Sub
>
> Private Sub UserForm_Activate()
> Me.TextBox1.SetFocus
> End Sub
> '**********************************
>
> 'My code for UserForm2:
> '**********************************
> Private Sub CommandButton1_Click()
> UserForm1.Show
> End Sub
>
> Private Sub UserForm_Activate()
> Me.TextBox1.SetFocus
> End Sub
> '**********************************
>
>
> "Mike" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Thanks Martin, but that doesn't seem to work.
>>
>> mike
>> "Martin Fishlock" <(E-Mail Removed)> wrote in message
>> news:1DD5ABD6-5E98-4585-8213-(E-Mail Removed)...
>>> Try using setfocus in the userform_activate on userform2
>>>
>>> Private Sub UserForm_Activate()
>>> Me.TextBox1.SetFocus
>>>
>>> End Sub
>>>
>>> --
>>> Hope this helps
>>> Martin Fishlock
>>> Please do not forget to rate this reply.
>>>
>>>
>>> "Mike" wrote:
>>>
>>>> Forgot to say that TextBox1 is in UserForm2.
>>>>
>>>> Mike
>>>>
>>>> "Mike" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>> >I have two MODELESS UserForms and I need to have the Textbox1 come up
>>>> >with
>>>> >the Focus when UserForm2 is Activated. Also, I need to leave UserForm2
>>>> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is
>>>> >LOADED
>>>> >(Button1), Textbox1 DOES come up with the Focus. However, after I HIDE
>>>> >it
>>>> >(Button2) and then reactivate it (Button1), the focus is gone. I can't
>>>> >seem
>>>> >to find and way of getting the focus back AUTOMATICALLY after the
>>>> >first
>>>> >Activation.
>>>> >
>>>> > IN USERFORM1:
>>>> > Private Sub CommandButton1_Click()
>>>> > Userform2.Show
>>>> > Userform2.Top = 300 'just to offset it from UserForm1
>>>> > End Sub
>>>> >
>>>> > Private Sub CommandButton2_Click()
>>>> > Userform2.Hide
>>>> > End Sub
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>>
>>>>
>>>>

>>
>>

>
>



 
Reply With Quote
 
Mark Ivey
Guest
Posts: n/a
 
      11th Dec 2006
Mike,

I see your problem, but I am drawing a blank as to why this is happening.



"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mark,
> Your code below doesn't have any HIDE and your buttons are NOT
> both in one form. Just copy the code I have below and put all of it in
> Userform1 Module. The textbox1 should be in UserForm2.
>
> mike
>
> "Mark Ivey" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Mike,
>>
>> Just gave it a quick once over and all worked fine for me (see my code
>> below). Can you give more detail on what problems you are having?
>>
>> 'My code for UserForm1:
>> '**********************************
>> Private Sub CommandButton1_Click()
>> UserForm2.Show
>> End Sub
>>
>> Private Sub UserForm_Activate()
>> Me.TextBox1.SetFocus
>> End Sub
>> '**********************************
>>
>> 'My code for UserForm2:
>> '**********************************
>> Private Sub CommandButton1_Click()
>> UserForm1.Show
>> End Sub
>>
>> Private Sub UserForm_Activate()
>> Me.TextBox1.SetFocus
>> End Sub
>> '**********************************
>>
>>
>> "Mike" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Thanks Martin, but that doesn't seem to work.
>>>
>>> mike
>>> "Martin Fishlock" <(E-Mail Removed)> wrote in message
>>> news:1DD5ABD6-5E98-4585-8213-(E-Mail Removed)...
>>>> Try using setfocus in the userform_activate on userform2
>>>>
>>>> Private Sub UserForm_Activate()
>>>> Me.TextBox1.SetFocus
>>>>
>>>> End Sub
>>>>
>>>> --
>>>> Hope this helps
>>>> Martin Fishlock
>>>> Please do not forget to rate this reply.
>>>>
>>>>
>>>> "Mike" wrote:
>>>>
>>>>> Forgot to say that TextBox1 is in UserForm2.
>>>>>
>>>>> Mike
>>>>>
>>>>> "Mike" <(E-Mail Removed)> wrote in message
>>>>> news:(E-Mail Removed)...
>>>>> >I have two MODELESS UserForms and I need to have the Textbox1 come up
>>>>> >with
>>>>> >the Focus when UserForm2 is Activated. Also, I need to leave
>>>>> >UserForm2
>>>>> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is
>>>>> >LOADED
>>>>> >(Button1), Textbox1 DOES come up with the Focus. However, after I
>>>>> >HIDE it
>>>>> >(Button2) and then reactivate it (Button1), the focus is gone. I
>>>>> >can't seem
>>>>> >to find and way of getting the focus back AUTOMATICALLY after the
>>>>> >first
>>>>> >Activation.
>>>>> >
>>>>> > IN USERFORM1:
>>>>> > Private Sub CommandButton1_Click()
>>>>> > Userform2.Show
>>>>> > Userform2.Top = 300 'just to offset it from UserForm1
>>>>> > End Sub
>>>>> >
>>>>> > Private Sub CommandButton2_Click()
>>>>> > Userform2.Hide
>>>>> > End Sub
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>>
>>>>>
>>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      11th Dec 2006
I think it is something to do the modeless nature of the forms.

A solution is to unload the form and reload it every time that you want to
use as follows:

Option Explicit

Private Sub CommandButton1_Click()
UserForm2.Show
UserForm2.Top = 300 'just to offset it from UserForm1
UserForm2.TextBox1.SetFocus
End Sub

Private Sub CommandButton2_Click()
UserForm2.Hide
Unload UserForm2
End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Mark Ivey" wrote:

> Mike,
>
> I see your problem, but I am drawing a blank as to why this is happening.
>
>
>
> "Mike" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Mark,
> > Your code below doesn't have any HIDE and your buttons are NOT
> > both in one form. Just copy the code I have below and put all of it in
> > Userform1 Module. The textbox1 should be in UserForm2.
> >
> > mike
> >
> > "Mark Ivey" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> >> Mike,
> >>
> >> Just gave it a quick once over and all worked fine for me (see my code
> >> below). Can you give more detail on what problems you are having?
> >>
> >> 'My code for UserForm1:
> >> '**********************************
> >> Private Sub CommandButton1_Click()
> >> UserForm2.Show
> >> End Sub
> >>
> >> Private Sub UserForm_Activate()
> >> Me.TextBox1.SetFocus
> >> End Sub
> >> '**********************************
> >>
> >> 'My code for UserForm2:
> >> '**********************************
> >> Private Sub CommandButton1_Click()
> >> UserForm1.Show
> >> End Sub
> >>
> >> Private Sub UserForm_Activate()
> >> Me.TextBox1.SetFocus
> >> End Sub
> >> '**********************************
> >>
> >>
> >> "Mike" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> Thanks Martin, but that doesn't seem to work.
> >>>
> >>> mike
> >>> "Martin Fishlock" <(E-Mail Removed)> wrote in message
> >>> news:1DD5ABD6-5E98-4585-8213-(E-Mail Removed)...
> >>>> Try using setfocus in the userform_activate on userform2
> >>>>
> >>>> Private Sub UserForm_Activate()
> >>>> Me.TextBox1.SetFocus
> >>>>
> >>>> End Sub
> >>>>
> >>>> --
> >>>> Hope this helps
> >>>> Martin Fishlock
> >>>> Please do not forget to rate this reply.
> >>>>
> >>>>
> >>>> "Mike" wrote:
> >>>>
> >>>>> Forgot to say that TextBox1 is in UserForm2.
> >>>>>
> >>>>> Mike
> >>>>>
> >>>>> "Mike" <(E-Mail Removed)> wrote in message
> >>>>> news:(E-Mail Removed)...
> >>>>> >I have two MODELESS UserForms and I need to have the Textbox1 come up
> >>>>> >with
> >>>>> >the Focus when UserForm2 is Activated. Also, I need to leave
> >>>>> >UserForm2
> >>>>> >Loaded so I just use SHOW and HIDE. The PROBLEM: When UserForm2 is
> >>>>> >LOADED
> >>>>> >(Button1), Textbox1 DOES come up with the Focus. However, after I
> >>>>> >HIDE it
> >>>>> >(Button2) and then reactivate it (Button1), the focus is gone. I
> >>>>> >can't seem
> >>>>> >to find and way of getting the focus back AUTOMATICALLY after the
> >>>>> >first
> >>>>> >Activation.
> >>>>> >
> >>>>> > IN USERFORM1:
> >>>>> > Private Sub CommandButton1_Click()
> >>>>> > Userform2.Show
> >>>>> > Userform2.Top = 300 'just to offset it from UserForm1
> >>>>> > End Sub
> >>>>> >
> >>>>> > Private Sub CommandButton2_Click()
> >>>>> > Userform2.Hide
> >>>>> > End Sub
> >>>>> >
> >>>>> >
> >>>>> >
> >>>>> >
> >>>>> >
> >>>>>
> >>>>>
> >>>>>
> >>>
> >>>
> >>
> >>

> >
> >

>
>
>

 
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
setfocus on textbox seeker Microsoft Access Form Coding 8 2nd Oct 2009 12:57 AM
Setfocus on textbox Jason Microsoft Access Forms 3 26th May 2008 03:30 PM
textbox setfocus Ong Won Yee Microsoft Dot NET Framework 0 14th Sep 2004 07:56 AM
Textbox.SetFocus Warrio Microsoft Access Form Coding 2 17th Jul 2003 06:08 PM
textbox.setfocus Warrio Microsoft Access Forms 0 17th Jul 2003 05:41 PM


Features
 

Advertising
 

Newsgroups
 


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