Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default restrict entry in a textbox to a range of values

I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default restrict entry in a textbox to a range of values

Dillonstar,

Data | Validation

You can put the allowed values in the appriopriate dialogs.

Regards,
Kevin

"Dillonstar" wrote in message
...
I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default restrict entry in a textbox to a range of values

Where is the textbox. Is it from the control toolbox toolbar or from the
drawing toolbar.

I assume it is on a userform and thus a control toolbox toolbar. You sound
like you are using the change event, but you probably want to use the Exit
Event.

You can use the keypress event to restrict entry to numbers and use the exit
event to check the number against your acceptable range.

Data|Validation is for cell entries if you want to move your input to the
worksheet.

--
Regards,
Tom Ogilvy

"Dillonstar" wrote in message
...
I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default restrict entry in a textbox to a range of values

Dillonstar,

I couldn't find the Data Validation for textboxes so...


Private Sub TextBox1_LostFocus()
Dim TBoxVal As Double
On Error GoTo ErrSec
If TextBox1.Value = "" Then Exit Sub
TBoxVal = CDbl(TextBox1.Value)
If TBoxVal < 9200000000# Or TBoxVal 9299999999# Then
TextBox1.Value = ""
MsgBox Prompt:="Your input was out of the range 9200000000" & _
vbCrLf & "& 9299999999. Please try again!"
TextBox1.Activate
Exit Sub
Else
Exit Sub
End If

ErrSec:
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate
End Sub


Allows the textbox to remain blank, if you don't want this remove the
If TextBox1.Value = "" Then Exit Sub

Does not allow non-numeric entry, if you want to have this remove the
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate

Dan E


"Dillonstar" wrote in message ...
I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default restrict entry in a textbox to a range of values

Dan,

You are right!

I need to slow down and read the question.

Regards,
Kevin


"Dan E" wrote in message
...
Dillonstar,

I couldn't find the Data Validation for textboxes so...


Private Sub TextBox1_LostFocus()
Dim TBoxVal As Double
On Error GoTo ErrSec
If TextBox1.Value = "" Then Exit Sub
TBoxVal = CDbl(TextBox1.Value)
If TBoxVal < 9200000000# Or TBoxVal 9299999999# Then
TextBox1.Value = ""
MsgBox Prompt:="Your input was out of the range 9200000000" & _
vbCrLf & "& 9299999999. Please try again!"
TextBox1.Activate
Exit Sub
Else
Exit Sub
End If

ErrSec:
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate
End Sub


Allows the textbox to remain blank, if you don't want this remove the
If TextBox1.Value = "" Then Exit Sub

Does not allow non-numeric entry, if you want to have this remove the
TextBox1.Value = ""
MsgBox Prompt:="Your input was non-numeric please try again!"
TextBox1.Activate

Dan E


"Dillonstar" wrote in message

...
I have a textbox that I want to restrict to a range of digits
(9200000000 - 9299999999).

I have tried various ways to bring up a message box when an incorrect
number has been entered, but everything I try seems to bring up the
error message AS you type, rather than when the complete number is
input.

I have managed to restrict to numerics and by field length sofar.

Can anyone help



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default restrict entry in a textbox to a range of values


Thanks for your replys everyone, though I haven't quite got it working
yet.

I should have been more specific, but Tom, you assumed correctly that
this is a textbox as part of a form. I have successfully protected the
field to only allow numerics, and have restricted the maxlength of the
field. I have yet to restrict to the values I stated earlier.

I changed 'TextBox1' to my assigned field name, 'txtBAN', however when
I run the form the debugger does not like the line:

txtBAN.Activate

Any additional help would be most appreciated.

Dillonstar


--
Dillonstar
------------------------------------------------------------------------
Dillonstar's Profile: http://www.excelforum.com/member.php...fo&userid=1814
View this thread: http://www.excelforum.com/showthread...hreadid=159534

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
Restrict data entry to specified cells ajsguinness Excel Worksheet Functions 2 June 11th 09 03:36 PM
Ideas on how to restrict a entry Alexandra Excel Discussion (Misc queries) 6 May 28th 09 11:16 PM
How to restrict entry or color the field mangesh Excel Discussion (Misc queries) 1 May 19th 06 11:16 PM
Restrict entry types Dolalu Excel Discussion (Misc queries) 1 November 29th 05 06:24 PM
can i restrict data entry from certain columns surgeandoj Excel Discussion (Misc queries) 1 July 8th 05 05:28 PM


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

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"