Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Date validation | Excel Discussion (Misc queries) | |||
Validation on date | Excel Worksheet Functions | |||
Date Validation for Date of Birth | Excel Programming | |||
Date Validation - Must equal Sundays date | Excel Discussion (Misc queries) | |||
Date Colum Date Formatting & Validation | Excel Programming |