Did you try the code I suggested?
On 09/09/2010 08:02, AccessDB wrote:
> On Sep 8, 6:02 pm, Dave Peterson<peter...@XSPAMverizon.net> wrote:
>> I like to have a routine that enables/disables the ok/continue button depending
>> on the validity of the input data.
>>
>> If the input data is bad, then the button is disabled. If the data is (er, are)
>> ok, then the button is enabled.
>>
>> And I like to use a Label to give an indication to the user what needs to be fixed.
>>
>> If that's sounds like something you'd like to try...
>>
>> Option Explicit
>> Private Sub CheckDates()
>>
>> Dim OkToContinue As Boolean
>>
>> Me.Label1.Caption = ""
>> OkToContinue = True
>>
>> If Year(Me.DTPicker1.Value)< 1990 _
>> Or Year(Me.DTPicker1.Value)> 2020 Then
>> OkToContinue = False
>> Me.Label1.Caption = "Please enter a good date in Date #1"
>> End If
>>
>> 'some basic validity to see if the date even makes sense
>> If Year(Me.DTPicker2.Value)< 1990 _
>> Or Year(Me.DTPicker2.Value)> 2020 Then
>> OkToContinue = False
>> Me.Label1.Caption = "Please enter a good date in Date #2"
>> End If
>>
>> If Me.DTPicker1.Value>= Me.DTPicker2.Value Then
>> OkToContinue = False
>> Me.Label1.Caption = "Date #2 must be bigger than Date #1"
>> End If
>>
>> Me.CommandButton2.Enabled = OkToContinue
>>
>> End Sub
>> Private Sub DTPicker1_Change()
>> Call CheckDates
>> End Sub
>> Private Sub DTPicker2_Change()
>> Call CheckDates
>> End Sub
>>
>> Private Sub UserForm_Initialize()
>> With Me.CommandButton1
>> .Caption = "Cancel"
>> .Enabled = True
>> End With
>>
>> With Me.CommandButton2
>> .Caption = "Ok"
>> .Enabled = False
>> End With
>>
>> Me.Label1.Caption = ""
>>
>> End Sub
>>
>> On 09/08/2010 16:34, AccessDB wrote:
>>
>>> I have 2 date time picker called DTPicker1 and DTPicker2. I'm using
>>> this in a userform and I have some questions:
>>> 1. Need code to force a user to have to pick a date in the pop up
>>> calendar. This applies to both DTPicker1 and DTPicker2.
>>
>>> 2. Need code to force DTPicker2 to be greater then DTPicker1. If it's
>>> not, there should be a msgbox and the focus should be on DTPicker2. If
>>> DTPicker2 is empty (no date picked) it should also no that no date is
>>> picked and a date greater than DTPicker1 is needed.
>>
>>> Can someone help?
>>
>> --
>> Dave Peterson
>
> Dave, I want a code to check for the dates picked from DTPicker1 and
> DTPicker2 when I click my Submit button(cmdSubmit). Ideally the code
> should check for:
> A - DTPicker1 should be equal to or greater than today's date.
> B - DTPicker2 should be equal to or greater than DTPicker1 date.
> C - Both date time picker must be picked or else a msgbox should pop
> (focus should be on the item not picked)up telling the user they must
> pick a date
>
> I'm not using any labels and only have a submit button that check the
> data validation of other textboxes as well. I do not want to have more
> than on command buttons.
>
> Is this a little more clear or do you need more details?
--
Dave Peterson
|