PC Review


Reply
Thread Tools Rate Thread

Date and Timer Picker question

 
 
AccessDB
Guest
Posts: n/a
 
      8th Sep 2010
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?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      9th Sep 2010
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
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      9th Sep 2010
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
 
Reply With Quote
 
AccessDB
Guest
Posts: n/a
 
      13th Sep 2010
On Sep 9, 11:42*am, "Harald Staff" <nos...@not.invalid> wrote:
> "AccessDB" <scl1...@gmail.com> wrote in message
>
> news:e4f8060d-aae8-4617-a36e-(E-Mail Removed)...
>
> > Is this a little more clear or do you need more details?

>
> That is a strangequestion. Dave's code does everything you ask for, except
> the nagging Msgbox. Nagging msgboxes is beginner programming. A more elegant
> solution, provided, is to make it impossible to click the commandbutton
> unless the input is valid. As seen on end user license agreements and other
> self explaining user interfaces.
>
> Best wishes Harald


Sorry for the late response. Thank you for the code. With little
modification, I made it to work.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Picker question h2fcell Microsoft Access Forms 1 13th Nov 2009 04:14 AM
Date Picker Question PostWise Microsoft Access Forms 2 15th Mar 2006 12:46 AM
Date Picker - Question Gina Microsoft Access Form Coding 0 29th Mar 2005 08:59 PM
Date and timer picker jz Microsoft Access VBA Modules 0 15th Aug 2003 06:03 AM
Date and timer picker jz Microsoft Access VBA Modules 0 15th Aug 2003 06:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:11 AM.