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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control should be easy!!!!!!!

Status
Not open for further replies.

DaveMac

Technical User
Apr 9, 2000
161
0
0
US
I have a form with a Start_Date and End_Date. When either get the Focus I want the calendar to appear. Once a date is selected disappear. I would like to reuse this item in all my projects and understand that passing the originator is important. Also have read that making the calendar appear and disappear after a date is selected may be a problem if the calendar defaults to Date() and the user is trying to select today.

Option Compare Database
Option Explicit

Dim Calendar_Originator As ComboBox ‘Tells who started the Calender

Private Sub Start_Date_Combo_GotFocus()
Calendar.Visible = True
Calendar.SetFocus
If Not IsNull(Start_Date_Combo) Then
Calendar.Value = Start_Date_Combo.Value
Else
Calendar.Value = Date
End If
End Sub

Private Sub Calendar_Click()
Start_Date_Combo.Value = Calendar.Value
Stop_Date_Combo.SetFocus ‘ Having problems with what to set the focus on
Calendar.Visible = False

Set Calendar_Originator = Nothing

End Sub





Thanks
 
Hi DaveMac ...

Option Compare Database
Option Explicit

Dim Calendar_Originator As ComboBox ‘Tells who started the Calender

Private Sub Start_Date_Combo_GotFocus()
Calendar.Visible = True
Calendar.SetFocus
If Not IsNull(Start_Date_Combo) Then
Calendar.Value = Start_Date_Combo.Value
Else
Calendar.Value = Date
End If
End Sub

Private Sub Calendar_Click()
Start_Date_Combo.Value = Calendar.Value
Stop_Date_Combo.SetFocus ‘ Having problems with what to set the focus on
Calendar.Visible = False

Set Calendar_Originator = Nothing

End Sub

... is changed to this ...

Option Compare Database
Option Explicit

Private Sub start_date_combo_GotFocus()
Calendar.Visible = True
Calendar.Value = IIf((IsNull(start_date_combo)), Now(), start_date_combo.Value)
End Sub

Private Sub Calendar_Click()
start_date_combo.Value = Calendar.Value
Screen.PreviousControl.SetFocus
Calendar.Visible = False
End Sub

If you need anything else, leave me a post. :)

Greg

If you don't understand, just nod and smile ...
 
Why don't you consider using the Microsoft DateTimePicker activeX control for each control? It should do exactly what you want.
 
evalesthy - I do not have that ActiveX Date_Time_Picker

grtammi- Here is what I have now but when it runs I get a error (Expected; End of Statement)


Option Compare Database
Option Explicit

Dim Calendar_Originator As ComboBox ‘Tells who started the Calender

Private Sub start_date_combo_GotFocus()
Calendar.Visible = True ‘ Show the Calendar when GotFocus
Calendar.Value = IIf((IsNull(Start_Date_Combo)), Now(), Start_Date_Combo.Value)
‘If Start_Date has a date set the calendar to that date if not set to today
End Sub


Private Sub Calendar_Click()
Start_Date_Combo.Value = Calendar.Value
Screen.PreviousControl.SetFocus
Calendar.Visible = False
Set Calendar_Originator = Nothing ‘ Clear the variable
End Sub

Thanks for all the help
 
What line are you erroring out on? This worked fine on my end when I tested it ... If you don't understand, just nod and smile ...
 
Greg,
I’m sorry it does work. Well it doesn’t work but it doesn’t crap out. It just doesn’t pass the date back to the Start_Date.


Thanks,
Dave
 
DaveMac

I gave up trying to use the ActiveX Date and Time Picker control because of errors it kept throwing up when trying to create a new record on the form, especially

Can’t set Value to NULL when Checkbox Property = FALSE

I now use a text box to show the date (bound to the date field) with a command button alongside to activate the Calendar Control 10.0, which works a treat. The code I use is:

-----------------------------------
Private Sub Calendar_Click()
Me.Start_Date = Me.Calendar.Value
Me.Start_Date.SetFocus
Me.Calendar.Visible = False
End Sub

------------------------------------

Private Sub cmdStart_Date_Click()
On Error GoTo Err_cmdStart_Date_Click

Me.Calendar.Visible = True

If Not IsNull(Me.Start_Date) Then
Me.Calendar.Value = Me.Start_Date
Else
Me.Calendar.Value = Date
End If

Exit_cmdStart_Date_Click:
Exit Sub

Err_cmdStart_Date_Click:
MsgBox Err.Description
Resume Exit_cmdStart_Date_Click


End Sub

-----------------------------------

Set the Visible property of the calendar control to No

Set the Default date of the Start_Date text box to

=Date()-1

and make sure the command button On Click even procedure is activated.

Try this and see if works as well for you!

JR
 
Hey guys, i've been watching your thread. i need the exact same thing on a form that i'm working on. i'm not good with vb code and i've gotten a little confused. where does your first line of code go? does it go under the OnFocus event? or does it all get grouped together? i'm confused there. is the second line of code for the command button that uses the calender. i should be able to just copy and paste the code and change a few things to match my application right?

secondly, i don't have the calendar control 10.0. i have 9.0. How do i specify this, if i need to at all. Sorry for all my dumb questions, just a little confused.

-Kevin531
 
Kevin:

First off, the only "dumb" question is the one that isn't asked.

Second, for a quick example how this calendar works, you can e-mail me at gtammi@atsbell.com and I will send you the basics. :)

Greg


If you don't understand, just nod and smile ...
 
DaveMac, I have a working calendar that you can use as doubleclick, Afterupdate or on got focus. It works just like you want it to. email me if you want it

akolln@megalink.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top