Embedded Calendar

  • Thread starter Thread starter Bruce Hudson via OfficeKB.com
  • Start date Start date
B

Bruce Hudson via OfficeKB.com

I am making a protected word form, which requires several date entries. I
would like to have a small drop down calendar, to select a date and fill in
the field. I see them on websights, quicken etc...
 
It's a bit more complex than you might imagine, but not really too
difficult. You will need to use a Userform in conjunction with the form
that you have in the protected document. For the basics, see the article
"How to create a Userform" at:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Name the userform "Calendar" and instead of adding text boxes to it, add a
Calendar control. To get this, you will need to right click on the toolbox
in the Visual Basic Editor and select the Additional Controls item. In the
dialog that appears, click on the box next to the calendar control and it
will then be added to the toolbox. When it is there, you can then add it to
the user form. By default, it will be assigned the name of Calendar1. You
will also need a Command Button on the user form and after you add that,
select it and then right click on it and select the View Code item and then
add the following code to the Click event:

Private Sub CommandButton1_Click()

ActiveDocument.FormFields("TxtDate").Result = Format(Calendar1, "d MMMM
yyyy")
Calendar.hide

End Sub

Next, in the template from which your protected form is being created,
create a macro name showcalendar() containing the following code

Sub showcalendar()

Calendar.Show

End Sub

Finally, in the properties dialog for the formfield on your protected form,
change the name of the bookmark assigned to the formfield to TxtDate and
from the Run Macro on Entry pulldown, select the Showcalendar macro.

Now, if you got all of this correct, when you protect the form and tab into
the TxtDate formfield, the userform with the calendar will be displayed.
When you select a date on the calendar and then click on the command button,
the selected date will be inserted into the TxtDate formfield.

I warned you that there was a bit more to it than you might think. Post
back if you have any problems.
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
Doug,

I'm close!!! Two problems though...

1. As I tab through several fields in the document, the calendar pops up
on each one, but when I make a selection the new date goes into the first
date field in the document. The remaining fields remain blank.

2. After selecting a date for a field, I can't click on the filled in
field and select a new date.

Thanks


It's a bit more complex than you might imagine, but not really too
difficult. You will need to use a Userform in conjunction with the form
that you have in the protected document. For the basics, see the article
"How to create a Userform" at:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

Name the userform "Calendar" and instead of adding text boxes to it, add a
Calendar control. To get this, you will need to right click on the toolbox
in the Visual Basic Editor and select the Additional Controls item. In the
dialog that appears, click on the box next to the calendar control and it
will then be added to the toolbox. When it is there, you can then add it
to
the user form. By default, it will be assigned the name of Calendar1. You
will also need a Command Button on the user form and after you add that,
select it and then right click on it and select the View Code item and then
add the following code to the Click event:

Private Sub CommandButton1_Click()

ActiveDocument.FormFields("TxtDate").Result = Format(Calendar1, "d MMMM
yyyy")
Calendar.hide

End Sub

Next, in the template from which your protected form is being created,
create a macro name showcalendar() containing the following code

Sub showcalendar()

Calendar.Show

End Sub

Finally, in the properties dialog for the formfield on your protected form,
change the name of the bookmark assigned to the formfield to TxtDate and
from the Run Macro on Entry pulldown, select the Showcalendar macro.

Now, if you got all of this correct, when you protect the form and tab into
the TxtDate formfield, the userform with the calendar will be displayed.
When you select a date on the calendar and then click on the command
button,
the selected date will be inserted into the TxtDate formfield.

I warned you that there was a bit more to it than you might think. Post
back if you have any problems.
I am making a protected word form, which requires several date entries. I
would like to have a small drop down calendar, to select a date and fill
in
the field. I see them on websights, quicken etc...

Reply
 
For 1., it sounds like you must have the Macro to run on entry to each of
those fields set to the one that calls the userform.

For 2., it will be necessary to tab into the formfield to get the macro that
calls the userform to fire.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
Back
Top