PDA

View Full Version : MULTIPLE CALENDARS



Greg
08-10-2007, 10:18 PM
Hi all,

Somewhere in this forum I found an active X button and popup calendar which I have used successfully in my document.

I now wish to use the Calendar to insert different dates in 2 places of the document.

I have created 2 command buttons cmdDate and cmdDate2 and each of them will bring up the calendar but I cant get the second button to fill in the second bookmark.

I feel that the following code needs modification but my attempts so far have been unsuccessful.

Can anyone help?

[Option Explicit

Private Sub cal_Click()
Dim szDate As String
'Chr$(160) is a protected space, so that the Date stays together on a line
szDate = Format(cal.Value, "d" & Chr$(160) & "mmmm" & Chr$(160) & "yyyy")
ActiveDocument.FormFields("txtCourseDate").Result = szDate
End Sub

Private Sub cal_LostFocus()
cal.Height = 0.5
End Sub

Private Sub cmdDate_Click()
DisplayCalendar
End Sub
Private Sub cmdDate2_Click()
DisplayCalendar2
End Sub

Sub CommandButton1_Click()
Dim oField As Word.Field
For Each oField In ActiveDocument.Fields()
oField.Update
Next
End Sub
]

fionabolt
08-13-2007, 01:32 AM
Greg,

It's difficult to tell from the code snippet you have provided, but are you unloading the first instance of the calendar after you've finished with it and before you load the 2nd instance?

F

clhare
08-14-2007, 05:16 AM
I do something similar, but I don't use bookmarks and I only use one calendar.

In the document itself I insert placeholder text (such as (Date1), (Date2), etc.). Then I have a userform with textboxes to get the dates. Each time I tab or click in a date textbox on the userform, the calendar form is brought up. Once a date is selected, it is entered into the textbox on the form. When I hit the OK button, the dates are inserted into the document at the placeholders.

I've attached a sample template. Hopefully it will be of some help.

fionabolt
08-14-2007, 05:26 AM
The template you attached is missing the calendar object, so not possible to de-bug it.

clhare
08-14-2007, 06:03 AM
I'm not sure I understand. What is missing?

clhare
08-14-2007, 06:13 AM
With the Toolbox displayed, I selected Tools > Additional Controls, then clicked on Calendar Control 8.0. Does that help?

fionabolt
08-14-2007, 06:48 AM
Hmm, that's new to me! Looks interesting tho, so I will look into it further when I have time....

I have Calendar Control 11.0, If I pre-select that the form crashes on loading, and then fatally crashes my Word app.:doh:

Hopefully another forum reader who has used this functionality before will be able to help you....

clhare
08-14-2007, 11:21 AM
Just wondering...can you just use the code and put in your own calendar form instead of mine? Would the code reference your calendar form if you name it the same and then run correctly?

fionabolt
08-15-2007, 12:18 AM
I tried that, and Word fatally crashes. You'll need to hope that someone who has used this functionality responds.

In your initial query you said:

Somewhere in this forum I found an active X button and popup calendar which I have used successfully in my document.

It might be worth contacting the original poster of that thread?

clhare
08-15-2007, 04:43 AM
Actually it works just fine for me, but if anyone else would like to try it and does not have the same control version I do (Calendar Control 8.0), I've reattached it without the calendar control on the form. You would need to insert your own calendar onto frmCalendar and name the control calTimeTrack.

Will it work for you now?

fionabolt
08-15-2007, 06:40 AM
Thanks for the extra info, I have it working now.

This is a great tool - wish I'd known about it before!

In the version I am working with, your code works just fine. I put in two different dates, and both get imported into the correct position in the Word document.

Have you tested the example code you provided? Maybe you have made a simple mistake in the actual code you are working on?

F

clhare
08-15-2007, 09:17 AM
It works as is for me. Did you have to change anything else to make it work?

Greg
08-19-2007, 03:27 AM
So that you all know what I am working with I have attaced the ActiveXsample thatI originally referred to.