Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default userform-check data type

I am developing a userform in which the user will enter a date. I want the
code to verify that the data entered is a valid date (type dbDate) before
calling the procedure. To do this I have been working with the code below:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtHol As Variant
dtHol = TextBox1.Value
If TextBox1.Type < dbDate And TextBox1.Value < "" Or _
TextBox1.Value < 0 Then
Call errMsg1
End If
End Sub

The Type method does not seem to be available for this purpose, and
assigning a variable the value of the TextBox has been similarly
unsuccessful. Any hints how this should be done?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default userform-check data type


If Not IsDate(TextBox1.Text) And TextBox1.Value < "" Or _
TextBox1.Value < 0 Then


--

HTH

RP
(remove nothere from the email address if mailing direct)


"xlcharlie" wrote in message
...
I am developing a userform in which the user will enter a date. I want

the
code to verify that the data entered is a valid date (type dbDate) before
calling the procedure. To do this I have been working with the code

below:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtHol As Variant
dtHol = TextBox1.Value
If TextBox1.Type < dbDate And TextBox1.Value < "" Or _
TextBox1.Value < 0 Then
Call errMsg1
End If
End Sub

The Type method does not seem to be available for this purpose, and
assigning a variable the value of the TextBox has been similarly
unsuccessful. Any hints how this should be done?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default userform-check data type

A textbox returns a string, so you can't test the type property (which a
textbox doesn't have a type property) against any constant. A constant such
as dbDate must be defined in a library other than Excel, Officer or MSForms,
so it would have little utility in such a check if it were possible.

Dim dt as Date
on Error Resume Next
dt = cDate(Textbox1.Text)
On Error goto 0

now check out dt to see if it meets your criteria.

--
Regards,
Tom Ogilvy



"xlcharlie" wrote in message
...
I am developing a userform in which the user will enter a date. I want

the
code to verify that the data entered is a valid date (type dbDate) before
calling the procedure. To do this I have been working with the code

below:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtHol As Variant
dtHol = TextBox1.Value
If TextBox1.Type < dbDate And TextBox1.Value < "" Or _
TextBox1.Value < 0 Then
Call errMsg1
End If
End Sub

The Type method does not seem to be available for this purpose, and
assigning a variable the value of the TextBox has been similarly
unsuccessful. Any hints how this should be done?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default userform-check data type

Try this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim dtHol As Variant
Dim dbDate As Date

dtHol = TextBox1.Value
If IsDate(TextBox1) < True And (TextBox1.Value < "" Or _
TextBox1.Value < 0) Then
MsgBox "Value must be date (mm/dd/yyyy)."
Cancel = True
End If

End Sub


"xlcharlie" wrote in message
...
I am developing a userform in which the user will enter a date. I want

the
code to verify that the data entered is a valid date (type dbDate) before
calling the procedure. To do this I have been working with the code

below:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtHol As Variant
dtHol = TextBox1.Value
If TextBox1.Type < dbDate And TextBox1.Value < "" Or _
TextBox1.Value < 0 Then
Call errMsg1
End If
End Sub

The Type method does not seem to be available for this purpose, and
assigning a variable the value of the TextBox has been similarly
unsuccessful. Any hints how this should be done?



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
check spelling as you type dp New Users to Excel 5 February 3rd 10 07:00 PM
Check for error.type in same cell art Excel Worksheet Functions 2 May 13th 09 06:14 AM
UserForm value check Dan Excel Programming 1 November 1st 04 05:21 PM
How to check a Variant for its data type TBA[_2_] Excel Programming 5 January 9th 04 11:04 PM
Type of textbox on userform Lieven Mettepenningen[_2_] Excel Programming 2 October 15th 03 01:36 PM


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