By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Highlight the date on the calendar control

P: n/a
Hi all,

I have a masked text control that would return a date in string format via
the mask property like:

"9/23/2004"

and i have a calendar control that would pop up when I click a command
button, I know the masked text control always returns a valid date. How do I
code in the command click to highlight the correct date on calendar control?
Which date functions do I need, if I need any at all?

for example:
'--------------------------------------
private sub command1_click()
calendar.visibled = true
calendar1.day =
calendar1.month =
calendar1.year =

End Sub
'--------------------------------------

thanks all
Jing.
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Jing,

Assuming that the calendar is the default ActiveX calendar control that
ships with Access...
Try this code (tested and working ... but you'll have to edit control names
to match your controls of course)

****************************
Private Sub Command1_Click()

Dim varDate
varDate = Me![YourTextBoxControl]

If IsDate(varDate) Then
Me![YourCalendarControl].Visible = True
Me![YourCalendarControl].Value = varDate
Me.Refresh
Else
Me![YourCalendarControl].Visible = False
MsgBox ("You must enter a valid date in YourTextBoxControl.")
Me![YourTextBoxControl] = "" 'This line is optional ... clears the
incorrect entry.
Me![YourTextBoxControl].SetFocus
End If

End Sub
****************************

--
HTH,
Don
=============================
E-Mail (if you must)
My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"JingleBEV" <n_****@NOSPAMyahoo.com> wrote in message
news:1j*******************@news20.bellglobal.com.. .
Hi all,

I have a masked text control that would return a date in string format via
the mask property like:

"9/23/2004"

and i have a calendar control that would pop up when I click a command
button, I know the masked text control always returns a valid date. How do I code in the command click to highlight the correct date on calendar control? Which date functions do I need, if I need any at all?

for example:
'--------------------------------------
private sub command1_click()
calendar.visibled = true
calendar1.day =
calendar1.month =
calendar1.year =

End Sub
'--------------------------------------

thanks all
Jing.

Nov 13 '05 #2

P: n/a
Don,
Thanks for the quick response. I figured it out and it works, the code looks
like this:
'***************************
Private Sub Command1_Click()
Dim d As Date
Calendar1.Visible = Not Calendar1.Visible
d = CDate(txtCalendar.Mask)
Calendar1.Day = DatePart("d", d)
Calendar1.Month = DatePart("m", d)
Calendar1.Year = DatePart("yyyy", d)
End Sub
'*************************************
I already know that it's a valid date, because it's generated by the
calendar control.

"Don Leverton" <le****************@telusplanet.net> wrote in message
news:s62Gc.50444$l6.46894@clgrps12...
Hi Jing,

Assuming that the calendar is the default ActiveX calendar control that
ships with Access...
Try this code (tested and working ... but you'll have to edit control names to match your controls of course)

****************************
Private Sub Command1_Click()

Dim varDate
varDate = Me![YourTextBoxControl]

If IsDate(varDate) Then
Me![YourCalendarControl].Visible = True
Me![YourCalendarControl].Value = varDate
Me.Refresh
Else
Me![YourCalendarControl].Visible = False
MsgBox ("You must enter a valid date in YourTextBoxControl.")
Me![YourTextBoxControl] = "" 'This line is optional ... clears the
incorrect entry.
Me![YourTextBoxControl].SetFocus
End If

End Sub
****************************

--
HTH,
Don
=============================
E-Mail (if you must)
My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code
samples are also Access97- based
unless otherwise noted.

Do Until SinksIn = True
File/Save, <slam fingers in desk drawer>
Loop

================================

"JingleBEV" <n_****@NOSPAMyahoo.com> wrote in message
news:1j*******************@news20.bellglobal.com.. .
Hi all,

I have a masked text control that would return a date in string format via the mask property like:

"9/23/2004"

and i have a calendar control that would pop up when I click a command
button, I know the masked text control always returns a valid date. How
do I
code in the command click to highlight the correct date on calendar

control?
Which date functions do I need, if I need any at all?

for example:
'--------------------------------------
private sub command1_click()
calendar.visibled = true
calendar1.day =
calendar1.month =
calendar1.year =

End Sub
'--------------------------------------

thanks all
Jing.


Nov 13 '05 #3

P: n/a
Hi "JingleBEV",

I'm confused...

Are you telling me that you:
----------------------------
1.) Select a date on the calendar which inserts the selected date value into
a textbox? (Is this a bound or unbound textbox? ... It sounds like a bound
field to me, now.)
2.) Then you use the command button to toggle the calendar's .Visible
Property? If it *is* visible when you click the button, it becomes
invisible, and vise-versa? If so, that seems bizarre to me ... why would you
want to do that?
3.) Next you use the date that you just inserted into the textbox to
"highlight" a date on your calendar?

If this textbox is a bound control, I'd suggest doing it this way:
-------------------------------------------------------------
1.) Test its value using the IsDate() function in the form's On Current
event.
2.) If it contains a valid date value, then assign the calendars .Value
property to the value in the textbox, which has the same effect as setting
your .Day, .Month, .Year properties as you have done below.
3.) This "test" could also be used to determine the calendar's .Visible
property. If it contains a valid date, display the calendar... if not, then
hide the calendar.

Don
"JingleBEV" <n_****@NOSPAMyahoo.com> wrote in message
news:tO*******************@news20.bellglobal.com.. .
Don,
Thanks for the quick response. I figured it out and it works, the code looks like this:
'***************************
Private Sub Command1_Click()
Dim d As Date
Calendar1.Visible = Not Calendar1.Visible
d = CDate(txtCalendar.Mask)
Calendar1.Day = DatePart("d", d)
Calendar1.Month = DatePart("m", d)
Calendar1.Year = DatePart("yyyy", d)
End Sub
'*************************************
I already know that it's a valid date, because it's generated by the
calendar control.

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.