Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Form, SetFocus and AfterUpdate issue

Hi all,
Small piece of validation on text box. If it's not 8 characters, clear the
text box and place the insertion point in the same text box.
The following in placed in the After_Update event:

Dim PN As String

PN = txtpolicynumber.Text

If Len(Policynumber) < 8 Then
Msgbox "Invalid Entry. Must be 8 digits long", vbOKOnly + vbCritical,
"Data Validation"
txtpolicynumber.Text = ""
txtpolicynumber.SetFocus
End If

This works *ok* in a command button, but *not* in the text box's
after_update event. It places the cursor in the next text box. I can only
assume that it is placing the focus in the required text box, but it is not
cancelling the tab event, and still moving to the next object.

Any ideas on how to cancel the tab? :-s

TIA,

Piers


  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Form, SetFocus and AfterUpdate issue

"harpscardiff"

is this starting to sound repetitious. Same advice you received yesterday.


--
Regards,
Tom Ogilvy


"Leith Ross" wrote
in message ...

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange issue freezing parent form when unloading a child form Stefano Gatto Excel Programming 1 November 11th 05 04:42 PM
setfocus on user form inquirer Excel Programming 7 May 17th 05 12:28 AM
AfterUpdate bforster1[_26_] Excel Programming 1 November 6th 04 07:16 PM
setfocus on multipage tab form gives error message Cheryl Excel Programming 3 July 28th 04 03:07 PM
SetFocus in user form John Tjia Excel Programming 6 February 2nd 04 03:05 PM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"