Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using Calendar Control to populate 2 fields

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
I have a form which asks the user for 2 dates, the form has 2 text box controls (D1 and D2) and an ActiveX CalendarControl. What i am trying to do is to make both D1 and D2 be populated form the CalendarControl. So the first date a user selects goes into D1 and the second goes into D2. Can this be done? Or is there a better way?

Cheers, Craig
Si fractum non sit, noli id reficere
 
You could check control D1 for IsNull and make a decision on where to update the date value.

Code for the pick of a date in the Calendar control
Code:
If IsNull(Me.D1) then
   [i][green]'put code to assign date value to D1[/green][/i]
Else
   [i][green]'put code to assign date value to D2[/green][/i]
End If

Must think through the need for overwriting a bad pick. If the user makes a pick and D1 is populated and then they want to make another pick for D1 this code will immediately through the pick to D2. Also, what to do if both fields are filled and a pick is made. Possibly a prompt.

Let me know what you think and if I can help work out the particulars of all the options let me know.


[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
I have a button on the screen called "DateButton"

I then assign the "caption" of the "DateButton" by a couple of different methods. When either of the fields (D1 or D2) that I want to add the date to gets focus.


Private Sub NeedDate_GotFocus()
' Set the DateButton value when user moves into "NeedDate" field.
' This can be done by mouse click or tab, etc.
DateButton.Caption = "Need Date"
End Sub
Private Sub ShipDate_GotFocus()
' Set the DateButton value when user moves into "ShipDate" field.
' This can be done by mouse click or tab, etc.
DateButton.Caption = "Ship Date"
End Sub

Or by clicking the "DateButton". This just toggles the value of DateButton.

Private Sub DateButton_Click()
If DateButton.Caption = "Ship Date" Then
DateButton.Caption = "Need Date"
Else
DateButton.Caption = "Ship Date"
End If
End Sub

I can then assign (click) the calendar as many times as I wish. Click on the calendar updates the field defined by the DateButton then toggles to the next value. (PS. this can be programmed for as many fields as you desire.)

If DateButton.Caption = "Need Date" Then
NeedDate = ActiveXCtl10.Value
DateButton.Caption = "Ship Date"
Else
ShpDate = ActiveXCtl10.Value
DateButton.Caption = "Need Date"
End If


Hope this helps!
Wes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top