View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default how to keep focus on txt_box in userform

Hi Jean-Pierre,

Try:

Option Explicit
Public blInvalidEntry As Boolean '<<=== Module level flag


Private Sub nw_premieNP_Exit(ByVal Cancel As MSForms.ReturnBoolean)
OnlyNumbers nw_premieNP
Cancel = blInvalidEntry <<============ ADDED
Worksheets("Sheet2").Range("G12") = nw_premieNP.Value
End Sub

Private Sub OnlyNumbers(ctl As Object)
With ctl
If Not IsNumeric(Left(.Value, 1)) And .Value < vbNullString Then
MsgBox "Sorry, alleen getallen toegestaan", _
vbOKOnly, "De Pensioen Adviseur """
.Value = vbNullString
blInvalidEntry = True
Else
blInvalidEntry = False
End If
End With
End Sub

---
Regards,
Norman



"Pierre via OfficeKB.com" wrote in message
...
Hi,

i have the following code for a txt_box on a userform:

Private Sub nw_premieNP_Exit(ByVal Cancel As MSForms.ReturnBoolean)
OnlyNumbers nw_premieNP
Worksheets("staffelberekening").Range("G12") = nw_premieNP.Value
End Sub

the Only numbers sub looks like

Private Sub OnlyNumbers(ctl As Object)
With ctl
If Not IsNumeric(Left(.Value, 1)) And .Value < vbNullString
Then
MsgBox "Sorry, alleen getallen toegestaan", vbOKOnly, "De
Pensioen
Adviseur"
.Value = vbNullString
.SetFocus
End If
End With
End Sub

The problem is that if the input is not numeric, the input is deleted but
the
focus is put on the next input box.
How can i have the focus on the field that was input wrong ?

thanks,
Pierre


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200509/1