Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Validating an entry on a user form

Hi,

I have a form that collects inputs from the user and verifies it against a
set of criteria.

As it stands at the moment, the code that does the evaluation is triggered
by the TextBox Exit event (when the user presses the enter key, tabs or
simply clicks elsewhere). This also causes the cursor to move on to the next
box in the tab index list.

How do I interrupt the tab index list in the event of an error (or point the
code back at the textBox in question) so that if the user inputs an invalid
value, the cursor remains in that TextBox?

TIA

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating an entry on a user form


Use SetFocus, something like this


Code:
--------------------
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me
If Not IsNumeric(.TextBox1.Value) Then
.TextBox1.Value = vbNullString
MsgBox "Only numeric entries allowed", vbCritical, "Input error"
.TextBox1.SetFocus
End If
End With
End Sub
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=41848

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Validating an entry on a user form

The Exit event declaration header automatically provides a Cancel
argument... if you don't want to exit the TextBox, just set Cancel=True
inside the appropriate section of your code.

--
Rick (MVP - Excel)


"Risky Dave" wrote in message
...
Hi,

I have a form that collects inputs from the user and verifies it against a
set of criteria.

As it stands at the moment, the code that does the evaluation is triggered
by the TextBox Exit event (when the user presses the enter key, tabs or
simply clicks elsewhere). This also causes the cursor to move on to the
next
box in the tab index list.

How do I interrupt the tab index list in the event of an error (or point
the
code back at the textBox in question) so that if the user inputs an
invalid
value, the cursor remains in that TextBox?

TIA

Dave


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Validating an entry on a user form


I didn't think of that, much neater


Code:
--------------------
Option Explicit

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If Not IsNumeric(.Value) Then
.Value = Empty
Cancel = True
End If
End With
End Sub
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=41848

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
clear user form after entry willfeld Excel Programming 11 May 1st 08 05:24 AM
user entry form for excel search DJTI Excel Programming 1 March 9th 07 05:50 PM
Auto email - With every new entry on my user form Vikram Excel Discussion (Misc queries) 0 June 19th 06 06:00 AM
Data Entry Alert in User Form Kev Excel Discussion (Misc queries) 6 January 8th 05 03:01 PM
USer Form Entry to multiple cells Jerry Eggleston Excel Programming 0 May 26th 04 12:20 AM


All times are GMT +1. The time now is 09:01 AM.

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

About Us

"It's about Microsoft Excel"