drop-down calendar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to get a drop down calendar in Word as a way to select a
required date. It would be nice if that could be set up as a form field.
Could it be done as a macro? If so, some help would be terrific.
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.


--
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
 
I have followed your instructions (thanks so much for going to all this
trouble, I've found a whole new world in Visual Basic Editor!!). However,
I'm stuck after creating the macro. That seems to work ok, but the next step
is giving me trouble. I seem to be unable to change the name of the bookmark
from Text1 to TxtDate as you indicated. When I run the macro, it simply
gives me the instruction of Sub showcalendar()
Calendar.Show
End Sub

Is this right? do I need to protect the form before it will 'look' right.
Just a bit muddled. I'm sure it's all fixable, but it's a bit beyond me with
the instructions as given.
Thanks again for your help, I've already learnt so much!
Cheers.
 
What if you want several drop down calendars in the same form? The date
keeps going to the one original field.
Regards
Norman
 
In that case, have a separate macro that runs on entry to each of the
formfields as follows

Dim oForm as frmCalendar

Set oForm = New frmCalendar
oForm.Show vbModal
ActiveDocument.FormFields("TxtDate").Result = Format(Calendar1, "d MMMM
yyyy")
' ----------------------------------
Unload oForm
Set oForm = Nothing

Changing the "TxtDate" to the name of the formfield from which the macro is
called, and in the command button click event of the userform, just have

Me.Hide
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
Doug
Running the macro, I get the following 'compile error: User-defined type not
defined' with the section "oForm As frmcalendar" highlighted.
I'm not the smartest with macros and don't know what this means.
Do you know what I'm doing wrong?
Regards
Norman
 
Doug,
I tried these instructions and I think there is an error in this paragraph:

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

Shouldn't the macro name be showcalendar?

I am also having a great deal of trouble with the CommandButton syntax.

I currently have:

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

BTW, when I originally copy/pasted your syntax, the yyyy") part kept showing
up like this: yyyy ") "
(Or maybe there was no space before the second quote mark. I don't want to
replicate it now.)

Anyway, the calendar is coming up and looks great, but the command button
doesn’t work.

I appreciate your help.

Regina
 
Fortunately, a former VB programmer happened along and helped me figure out
what I was doing wrong with the Command Button (which I named Save). Couldn't
tell you now exactly what we did.

However, I still have a problem. I set up the calendar on July 31, 2007, and
no matter what date I choose on the calendar, when I reopen the file, the
calendar defaults to July 31, 2007.

How can I change that?

Thanks!
Regina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top