View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_244_] Leith Ross[_244_] is offline
external usenet poster
 
Posts: 1
Default Form, SetFocus and AfterUpdate issue


Hello Piers 2k,

You need to place the macro in the Exit event and use Cancel. You can
copy and paste the updated macro into your project.


Code:
--------------------
Private Sub txtPolicynumber_Exit(ByVal Cancel As MSForms.ReturnBoolean)

L = Len(txtPolicynumber.Text)

If L 0 And L < 8 Then
Msgbox "Invalid Entry. Must be 8 digits long", vbOKOnly + vbCritical, "Data Validation"
Cancel = True
With txtPolicynumber
.SelStart = 0
.SelLength = L
.SetFocus
End With
End If

End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=483052