Home All Groups Group Topic Archive Search About

How do I put the focus back in a text box

Author
26 May 2005 3:44 PM
Dale
Hi all

This shoud be a simple problem to fix but it is perplexing me.

I have the following in my LostFocus event.

If the condition exists, I'd like the focus to go right back to the
CustomerDirectory textbox.


    If Not fs.FolderExists(CustomerDirectory.Text) Then

        MsgBox "Bad customer directory, try again", vbExclamation + vbOKOnly
        CustomerDirectory.Text = "J:\ML\"   ' set directory to default

    End If

    'CustomerDirectory_GotFocus     ' this doesn't work


Can anyone point me in the right direction?

Regards
Dale Jones

Author
26 May 2005 4:06 PM
Bryan Dickerson
CustomerDirectory.SetFocus

Show quoteHide quote
"Dale" <D-Man> wrote in message
news:eoHRvngYFHA.3132@TK2MSFTNGP09.phx.gbl...
> Hi all
>
> This shoud be a simple problem to fix but it is perplexing me.
>
> I have the following in my LostFocus event.
>
> If the condition exists, I'd like the focus to go right back to the
> CustomerDirectory textbox.
>
>
>    If Not fs.FolderExists(CustomerDirectory.Text) Then
>
>        MsgBox "Bad customer directory, try again", vbExclamation +
> vbOKOnly
>        CustomerDirectory.Text = "J:\ML\"   ' set directory to default
>
>    End If
>
>    'CustomerDirectory_GotFocus     ' this doesn't work
>
>
> Can anyone point me in the right direction?
>
> Regards
> Dale Jones
>
Author
26 May 2005 4:06 PM
Saga
One of two:

Use the txtCustomerDirectory.Setfocus event

Or better, move your validation code to the validate event and
if your validation does not pass mustard, return True in the Cancel
parameter.

But do not call the Got focus event directly, this event fires when
the control receives focus, but does not set focus.

Good luck!
Saga

Show quoteHide quote
"Dale" <D-Man> wrote in message
news:eoHRvngYFHA.3132@TK2MSFTNGP09.phx.gbl...
> Hi all
>
> This shoud be a simple problem to fix but it is perplexing me.
>
> I have the following in my LostFocus event.
>
> If the condition exists, I'd like the focus to go right back to the
> CustomerDirectory textbox.
>
>
>    If Not fs.FolderExists(CustomerDirectory.Text) Then
>
>        MsgBox "Bad customer directory, try again", vbExclamation +
> vbOKOnly
>        CustomerDirectory.Text = "J:\ML\"   ' set directory to default
>
>    End If
>
>    'CustomerDirectory_GotFocus     ' this doesn't work
>
>
> Can anyone point me in the right direction?
>
> Regards
> Dale Jones
>
Author
26 May 2005 4:52 PM
Saga
Correction:
    txtCustomerDirectory.Setfocus is a method, NOT event
Sorry

Saga

Show quoteHide quote
"Saga" <antiSpam@somewhere.com> wrote in message
news:Om3vezgYFHA.2128@TK2MSFTNGP15.phx.gbl...
>
>
> One of two:
>
> Use the txtCustomerDirectory.Setfocus event
>
> Or better, move your validation code to the validate event and
> if your validation does not pass mustard, return True in the Cancel
> parameter.
>
> But do not call the Got focus event directly, this event fires when
> the control receives focus, but does not set focus.
>
> Good luck!
> Saga
>
> "Dale" <D-Man> wrote in message
> news:eoHRvngYFHA.3132@TK2MSFTNGP09.phx.gbl...
>> Hi all
>>
>> This shoud be a simple problem to fix but it is perplexing me.
>>
>> I have the following in my LostFocus event.
>>
>> If the condition exists, I'd like the focus to go right back to the
>> CustomerDirectory textbox.
>>
>>
>>    If Not fs.FolderExists(CustomerDirectory.Text) Then
>>
>>        MsgBox "Bad customer directory, try again", vbExclamation +
>> vbOKOnly
>>        CustomerDirectory.Text = "J:\ML\"   ' set directory to default
>>
>>    End If
>>
>>    'CustomerDirectory_GotFocus     ' this doesn't work
>>
>>
>> Can anyone point me in the right direction?
>>
>> Regards
>> Dale Jones
>>
>
>
Author
26 May 2005 8:09 PM
Dale
Thanx  a lot guys.


Show quoteHide quote
"Dale" <D-Man> wrote in message
news:eoHRvngYFHA.3132@TK2MSFTNGP09.phx.gbl...
> Hi all
>
> This shoud be a simple problem to fix but it is perplexing me.
>
> I have the following in my LostFocus event.
>
> If the condition exists, I'd like the focus to go right back to the
> CustomerDirectory textbox.
>
>
>    If Not fs.FolderExists(CustomerDirectory.Text) Then
>
>        MsgBox "Bad customer directory, try again", vbExclamation +
> vbOKOnly
>        CustomerDirectory.Text = "J:\ML\"   ' set directory to default
>
>    End If
>
>    'CustomerDirectory_GotFocus     ' this doesn't work
>
>
> Can anyone point me in the right direction?
>
> Regards
> Dale Jones
>
Author
27 May 2005 12:21 AM
Michael Cole
Dale wrote:
Show quoteHide quote
> Hi all
>
> This shoud be a simple problem to fix but it is perplexing me.
>
> I have the following in my LostFocus event.
>
> If the condition exists, I'd like the focus to go right back to the
> CustomerDirectory textbox.
>
>
>     If Not fs.FolderExists(CustomerDirectory.Text) Then
>
>         MsgBox "Bad customer directory, try again", vbExclamation +
>         vbOKOnly CustomerDirectory.Text = "J:\ML\"   ' set directory
> to default

Oh, and slightly off-topic, I think your error messages could do with a bit
of work.

"Bad customer directory".  Naughty, naughty.  If you don't behave
properly...

Might I suggest something along the lines of, "Customer Directory is
Invalid."

Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/
error_message_guidelines.asp

--
Regards,

Michael Cole