Re: SetFocus on a userform Does Not Work

From: Jay Freedman (jay.freedman_at_verizon.net)
Date: 01/29/05


Date: Fri, 28 Jan 2005 21:52:24 -0500

Hi Don,

You're using the wrong event, that's all. Remove all the code from the
txtClientNumber_AfterUpdate handler and put it into the
txtClientNumber_Exit handler. That procedure has a boolean Cancel
argument. When the entry is invalid, set Cancel to True. That will
prevent the cursor from leaving the txtClientNumber control.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
On Fri, 28 Jan 2005 15:41:32 -0800, "Don" <dcardoza@gibbonslaw.com>
wrote:
>I have a fairly simple userform with a frame and two 
>textboxes inside the frame.  If a user makes an invalid 
>entry I want to display a message, clear the entry, and 
>set the focus back to the same field.
>
>The mesgbox displays perfectly, and the entry is cleared 
>fine.  However, the focus keeps going to the next textbox 
>in the frame.  I am getting frustrated!  I even tried 
>setting the focus back to the frame first, and then to the 
>field.  I also tried using the Exit event with no success.
>
>I am using the AfterUpdate event and the name of my 
>textbox is txtClientNumber.  My code appears below.
>
>Any ideas would be apprecaited.  Thanks so much in advance.
>
>
>Private Sub txtClientNumber_AfterUpdate()
>    
>    Dim StrClientName As String
>    Dim rstClientName As ADODB.Recordset
>    Set rstClientName = New ADODB.Recordset
>
>    StrClientName = "SELECT client_name FROM hbm_client 
>WHERE client_code = '" & txtClientNumber.Value & "'"
>
>    rstClientName.Open StrClientName, Main.cnn
>   
>    If rstClientName.EOF = True Then
>        MsgBox "That is an Invalid Client Number"
>        txtClientNumber.Value = Null
>        frmMain.fme1.SetFocus
>        txtClientNumber.SetFocus  '***PROBLEM HERE
>    Else
>        rstClientName.MoveFirst
>        txtClientName.Value = rstClientName
>("client_name").Value
>    End If
>        
>End Sub
>


Relevant Pages

  • Re: [PATCH][RFC] kprobes: Add user entry-handler in kretprobes
    ... have m kretprobe "misses", we may report n calls but only returns. ... allocation should be left to user entry handlers, ... 'ri' can uniquely identify any entry-return handler ... No. Handlers shouldn't be writing to the pt_regs struct unless they ...
    (Linux-Kernel)
  • Re: [PATCH][RFC] kprobes: Add user entry-handler in kretprobes
    ... I see no reason to save a copy of *regs and pass that to the entry ... And if a handler on i386 uses ®s->esp as the value of the ... stack pointer, ... Multiple kretprobe registration on the same function. ...
    (Linux-Kernel)
  • Re: Need to avoid "field X cannot contain a Null value"
    ... make no entry, or undo the entry ... Still in table design, ... I was hoping either someone already had working code or that ... add the next event handler." ...
    (microsoft.public.access.forms)
  • Re: [PATCH][RFC] kprobes: Add user entry-handler in kretprobes
    ... I accept that entry_handler() will execute each time process enters the function, but to calculate time, one needs to know corresponding instance of return probe handler. ... a one-to-one correspondence between the entry and return handlers ... In case someone wants to calculate the entry and exit timestamps of a ... pending return instances to reach the correct return instance. ...
    (Linux-Kernel)
  • Re: radio button question
    ... I created a KeyDown event handler and it works with one ... Radio buttons can be tricky. ... ..Net frame does) and disable the frame before manipulating the ...
    (microsoft.public.dotnet.framework.windowsforms.controls)