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

Hello. I have a problem that seems easy to solve but it has caused me some
trouble. I have a userform in which the user shall enter two main dates, one
start and one end date. The dates are entered in textboxes. If these dates
are Ok i.e. they are truely dates and not something else other textboxes
shall be populated with these dates. The user shall then have the opportunity
to change dates in these textboxes. After that the user presses a button and
the main program starts. This works fairly well for me. It works like this:
when the user enters something in the first "main" textbox i.e. startdate:

Private Sub TextBox1_Change()
Call IsEverythingValid
End Sub

Private Sub IsEverythingValid()
Dim AllOk As Boolean

AllOk = True
If IsDate(Me.TextBox1.Value) = False Then
AllOk = False
'Me.Label1.Caption = "Var god ange startdatum"
Else
If IsDate(Me.TextBox2.Value) = False Then
AllOk = False
' Me.Label1.Caption = "Var god ange slutdatum"
End If
End If

If AllOk = True Then
Call getInfoFromTextBox1
Call getInfoFromTextBox2
end if
Me.genereraRapportKnapp.Enabled = AllOk

End Sub

As you can see the sub checks if the dates are ok and if so activates the
button that starts the main program when pressed. the problem is that after
the user have entered a valid startdate and half of a valid end date my
program enables the button. I do not see why this would happen. It is a
problem because it looks bad and because I want to have a check to see if the
user has entered dates that are either a sunday or a saturday. Does anyone
know how to fix this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date validation

Excel will accept a partial date and apply some rules to complete it. for
example (from the immediate window):

? isdate("1/1")
True

If you are restricting to a specific format, you would need to put in a
check on length or perhaps two separators. You will probably need to write
something quite robust and test it thoroughly if you want a reliable
evaluation.

An alternative would be to use a datetimepicker type control.

--
Regards,
Tom Ogilvy


"Viktor Ygdorff" wrote:

Hello. I have a problem that seems easy to solve but it has caused me some
trouble. I have a userform in which the user shall enter two main dates, one
start and one end date. The dates are entered in textboxes. If these dates
are Ok i.e. they are truely dates and not something else other textboxes
shall be populated with these dates. The user shall then have the opportunity
to change dates in these textboxes. After that the user presses a button and
the main program starts. This works fairly well for me. It works like this:
when the user enters something in the first "main" textbox i.e. startdate:

Private Sub TextBox1_Change()
Call IsEverythingValid
End Sub

Private Sub IsEverythingValid()
Dim AllOk As Boolean

AllOk = True
If IsDate(Me.TextBox1.Value) = False Then
AllOk = False
'Me.Label1.Caption = "Var god ange startdatum"
Else
If IsDate(Me.TextBox2.Value) = False Then
AllOk = False
' Me.Label1.Caption = "Var god ange slutdatum"
End If
End If

If AllOk = True Then
Call getInfoFromTextBox1
Call getInfoFromTextBox2
end if
Me.genereraRapportKnapp.Enabled = AllOk

End Sub

As you can see the sub checks if the dates are ok and if so activates the
button that starts the main program when pressed. the problem is that after
the user have entered a valid startdate and half of a valid end date my
program enables the button. I do not see why this would happen. It is a
problem because it looks bad and because I want to have a check to see if the
user has entered dates that are either a sunday or a saturday. Does anyone
know how to fix this?

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
Date validation jpreman Excel Discussion (Misc queries) 7 October 30th 08 01:13 AM
Validation on date jk Excel Worksheet Functions 3 August 29th 06 01:30 AM
Date Validation for Date of Birth Stitch45 Excel Programming 2 March 5th 06 10:58 AM
Date Validation - Must equal Sundays date jeridbohmann Excel Discussion (Misc queries) 14 November 30th 05 08:40 PM
Date Colum Date Formatting & Validation Mike[_81_] Excel Programming 1 June 7th 04 01:59 AM


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