Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default validating dates on a userform

I have two text boxes on a user form, one start date and one end date. My
problem is that I need the right code for applying the validation to the text
boxes. They must fit the following criteria:

1. The start date can't be greater than the end date, and vice versus.
2. The dates entered in both fields can only be within a specific range of
dates (7/1/2009 through 7/31/2011). So the user won't be allowed to enter any
dates before or after this specific range.

If anyone has an idea please let me know.

Thanks,
~Gabe
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default validating dates on a userform

How about two comboboxes; that will limit the dates. As far as doing a
comparison, how about this:
If Me.cboNoTwo.Value < Me.cboNoOne.Value Then
MsgBox "Please make sure the ending date is greater than the beginning
date."
End If

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

I have two text boxes on a user form, one start date and one end date. My
problem is that I need the right code for applying the validation to the text
boxes. They must fit the following criteria:

1. The start date can't be greater than the end date, and vice versus.
2. The dates entered in both fields can only be within a specific range of
dates (7/1/2009 through 7/31/2011). So the user won't be allowed to enter any
dates before or after this specific range.

If anyone has an idea please let me know.

Thanks,
~Gabe

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default validating dates on a userform

Thanks, but two combo boxes would be a lot of trouble. Is there some code I
could use in VB that would limit the dates instead? I can duplicate what I am
trying to do in Excel with the validation tool:

=AND(ISNUMBER(A1),A1=DATE(2009,12,1),A1<=DATE(201 2,12,31),A1<=A2)

but I'm not sure about the code for the text boxes on the userform.

"ryguy7272" wrote:

How about two comboboxes; that will limit the dates. As far as doing a
comparison, how about this:
If Me.cboNoTwo.Value < Me.cboNoOne.Value Then
MsgBox "Please make sure the ending date is greater than the beginning
date."
End If

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

I have two text boxes on a user form, one start date and one end date. My
problem is that I need the right code for applying the validation to the text
boxes. They must fit the following criteria:

1. The start date can't be greater than the end date, and vice versus.
2. The dates entered in both fields can only be within a specific range of
dates (7/1/2009 through 7/31/2011). So the user won't be allowed to enter any
dates before or after this specific range.

If anyone has an idea please let me know.

Thanks,
~Gabe

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default validating dates on a userform

Try this:

Private Sub CommandButton1_Click()

Dim D1, D2 As Date
If CDate(TextBox1.Value) = CDate("07/01/2009") And CDate(TextBox2.Value) <=
CDate("07/31/2011") Then

D1 = DateValue(TextBox1.Text)
D2 = DateValue(TextBox2.Text)
Sheets(1).Range("B4").Value = D1
Sheets(1).Range("B5").Value = D2

Else

MsgBox "Invalid date entry. Please Enter dates b/w 07/01/2009 and 07/31/2011"

End If
End Sub




--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

Thanks, but two combo boxes would be a lot of trouble. Is there some code I
could use in VB that would limit the dates instead? I can duplicate what I am
trying to do in Excel with the validation tool:

=AND(ISNUMBER(A1),A1=DATE(2009,12,1),A1<=DATE(201 2,12,31),A1<=A2)

but I'm not sure about the code for the text boxes on the userform.

"ryguy7272" wrote:

How about two comboboxes; that will limit the dates. As far as doing a
comparison, how about this:
If Me.cboNoTwo.Value < Me.cboNoOne.Value Then
MsgBox "Please make sure the ending date is greater than the beginning
date."
End If

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

I have two text boxes on a user form, one start date and one end date. My
problem is that I need the right code for applying the validation to the text
boxes. They must fit the following criteria:

1. The start date can't be greater than the end date, and vice versus.
2. The dates entered in both fields can only be within a specific range of
dates (7/1/2009 through 7/31/2011). So the user won't be allowed to enter any
dates before or after this specific range.

If anyone has an idea please let me know.

Thanks,
~Gabe

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default validating dates on a userform

That worked great, I didn't need this part though...

D1 = DateValue(TextBox1.Text)
D2 = DateValue(TextBox2.Text)
Sheets(1).Range("B4").Value = D1
Sheets(1).Range("B5").Value = D2

Thanks again Ryan for all of your help!

"ryguy7272" wrote:

Try this:

Private Sub CommandButton1_Click()

Dim D1, D2 As Date
If CDate(TextBox1.Value) = CDate("07/01/2009") And CDate(TextBox2.Value) <=
CDate("07/31/2011") Then

D1 = DateValue(TextBox1.Text)
D2 = DateValue(TextBox2.Text)
Sheets(1).Range("B4").Value = D1
Sheets(1).Range("B5").Value = D2

Else

MsgBox "Invalid date entry. Please Enter dates b/w 07/01/2009 and 07/31/2011"

End If
End Sub




--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

Thanks, but two combo boxes would be a lot of trouble. Is there some code I
could use in VB that would limit the dates instead? I can duplicate what I am
trying to do in Excel with the validation tool:

=AND(ISNUMBER(A1),A1=DATE(2009,12,1),A1<=DATE(201 2,12,31),A1<=A2)

but I'm not sure about the code for the text boxes on the userform.

"ryguy7272" wrote:

How about two comboboxes; that will limit the dates. As far as doing a
comparison, how about this:
If Me.cboNoTwo.Value < Me.cboNoOne.Value Then
MsgBox "Please make sure the ending date is greater than the beginning
date."
End If

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Gabe" wrote:

I have two text boxes on a user form, one start date and one end date. My
problem is that I need the right code for applying the validation to the text
boxes. They must fit the following criteria:

1. The start date can't be greater than the end date, and vice versus.
2. The dates entered in both fields can only be within a specific range of
dates (7/1/2009 through 7/31/2011). So the user won't be allowed to enter any
dates before or after this specific range.

If anyone has an idea please let me know.

Thanks,
~Gabe

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
Validating Required Fields in Userform robinsn Excel Discussion (Misc queries) 0 July 24th 10 02:16 PM
Validating dates in a cell BrianG[_3_] Excel Programming 3 May 15th 07 10:06 PM
Validating Dates Entered patam Excel Discussion (Misc queries) 2 September 2nd 05 05:36 PM
Validating Dates Luis Verme Excel Programming 22 July 10th 05 11:41 AM
Event validating two ranges with dates G R E G Excel Programming 1 August 9th 03 12:03 AM


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