ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   validating dates on a userform (https://www.excelbanter.com/excel-programming/442546-validating-dates-userform.html)

gabe

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

ryguy7272

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


gabe

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


ryguy7272

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


gabe

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



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com