Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default textbox validation

I'm trying to validate user input in a userform textbox, based on a
value in a worksheet cell.
The following sub works fine:

Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBoxDay.Value 0 AND < 32 Then Exit Sub
MsgBox "Valid Days Only"
TextBoxDay = vbNullString
Cancel = True 'Keeps focus until value is null or correct
End Sub


However I cannot get the following code to work:

Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBoxDay.Value 0 AND TextBoxDay.Value < _
Worksheets("Begin").Cells(15, 9) Then Exit Sub
MsgBox "Valid Days Only"
TextBoxDay = vbNullString
Cancel = True 'Keeps focus until value is null or correct
End Sub


I've tried a number of variations but I can't seem to find a cell
reference that works. Worksheets("Begin").Cells(15, 9) = 32.

Thanks for any suggestions

Tim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default textbox validation


It's the darned string comparison issue again:

Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CInt(TextBoxDay.Value) 0 And TextBoxDay.Value < _
CInt(Worksheets("Begin").Cells(15, 9).Value) Then Exit Sub
MsgBox "Valid Days Only"
TextBoxDay = vbNullString
Cancel = True 'Keeps focus until value is null or correct
End Sub

The textbox.value property is a string value. Apparently excel looke
at the Cells().Value property and assumed it was also text.

You may want to do some preliminary checking to make sure the entere
value is numeric before running the compare or it will bomb if an alph
is entered.



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26871

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default textbox validation


Thanks KKKnie. That worked like a charm. I was completely oblivious
to the datatype difference. But I'll certainly watch out for that in
the future.

Tim

On Tue, 12 Oct 2004 19:43:54 -0500, kkknie
wrote:

It's the darned string comparison issue again:

Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CInt(TextBoxDay.Value) 0 And TextBoxDay.Value < _
CInt(Worksheets("Begin").Cells(15, 9).Value) Then Exit Sub
MsgBox "Valid Days Only"
TextBoxDay = vbNullString
Cancel = True 'Keeps focus until value is null or correct
End Sub

The textbox.value property is a string value. Apparently excel looked
at the Cells().Value property and assumed it was also text.

You may want to do some preliminary checking to make sure the entered
value is numeric before running the compare or it will bomb if an alpha
is entered.

K


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
Textbox validation TUNGANA KURMA RAJU Excel Discussion (Misc queries) 5 May 8th 09 11:15 PM
validation of input in textbox Peer Excel Programming 3 July 23rd 04 03:06 PM
textbox value validation girapas[_2_] Excel Programming 1 July 19th 04 12:16 PM
Textbox validation phreud[_17_] Excel Programming 6 June 27th 04 07:49 PM
textbox validation Beginner[_2_] Excel Programming 1 April 7th 04 07:46 PM


All times are GMT +1. The time now is 04:58 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"