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

hello all,

i am trying to put validation on a textbox in a userform. i currently have
this bit of code and it does not work. all i need is for it to except a 0 or
1 anything else would produce a message box stating that a 0 or 1 is needed.

Private Sub nailbase_Change()
If nailbase.Value 1 Then
MsgBox "Number must be a 0 or 1."
End Sub

--
Thank You in advance, Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default validation

Since you're only accepting 0 or 1, how about using a checkbox (0 if unchecked
or 1 if checked) -- or even a pair of option buttons.

I would think that it would be easier for the user and less work for you...

But Textboxes return strings:

Private Sub nailbase_Change()
If nailbase.Value = "1" _
or nailbase.value = "0" Then
'do nothing, it's ok
else
MsgBox "Number must be a 0 or 1."
end if
End Sub

Brian wrote:

hello all,

i am trying to put validation on a textbox in a userform. i currently have
this bit of code and it does not work. all i need is for it to except a 0 or
1 anything else would produce a message box stating that a 0 or 1 is needed.

Private Sub nailbase_Change()
If nailbase.Value 1 Then
MsgBox "Number must be a 0 or 1."
End Sub

--
Thank You in advance, Brian


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default validation

very good point Dave on using the check boxes. i will look into changing my
userform around. the code works good also. thank you for your time, and have
a good day.
--
Brian


"Dave Peterson" wrote:

Since you're only accepting 0 or 1, how about using a checkbox (0 if unchecked
or 1 if checked) -- or even a pair of option buttons.

I would think that it would be easier for the user and less work for you...

But Textboxes return strings:

Private Sub nailbase_Change()
If nailbase.Value = "1" _
or nailbase.value = "0" Then
'do nothing, it's ok
else
MsgBox "Number must be a 0 or 1."
end if
End Sub

Brian wrote:

hello all,

i am trying to put validation on a textbox in a userform. i currently have
this bit of code and it does not work. all i need is for it to except a 0 or
1 anything else would produce a message box stating that a 0 or 1 is needed.

Private Sub nailbase_Change()
If nailbase.Value 1 Then
MsgBox "Number must be a 0 or 1."
End Sub

--
Thank You in advance, Brian


--

Dave Peterson

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
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
Data validation with validation lists and combo boxs Keith Excel Discussion (Misc queries) 1 October 12th 06 11:08 AM
Validation (Drop down list vs simple text length validation) Bob Phillips[_6_] Excel Programming 2 April 27th 04 07:47 PM
Validation (Drop down list vs simple text length validation) Jason Morin[_2_] Excel Programming 1 April 27th 04 04:56 PM
Validation (Drop down list vs simple text length validation) Pete McCosh Excel Programming 0 April 27th 04 03:49 PM


All times are GMT +1. The time now is 02:18 AM.

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"