Word & Outlook Calendar

G

gary.cassidy

I have written a series of Word "boilerplate" letters. In one, a
custom dialog box including a calendar control "captures" the date the
user selects and writes it to a letter asking clients to attend an
interview. The time for the interview is entered by the user in a text
box. This too is entered in the letter however it is not validated in
any way. The section of those routines look like this

;Capture Date
Private Sub ctlCalendar_DateClick(ByVal DateClicked As Date)
datIntDate = Format(ctlCalendar.Value, "dddd, mmm d, yyyy")
lblDate.Caption = "Interview Date: " & vbCrLf & datIntDate
txtInterviewTime.SetFocus
End Sub

; Write Date in letter
With ActiveDocument
.Bookmarks("datIntDate").Range _
.InsertBefore datIntDate
.Bookmarks("datIntTime").Range _
.InsertBefore txtInterviewTime.Text & "."
End With


One of my co-workers came to me wondering if it was possible to have
the date automatically placed in Outlook once the letter is written.
My routines have all been very simple so I don't even know where to
begin. If it's fairly simple, I would appreciate any pointers in the
right direction.

Thanks

Gary
 
P

Perry

Following snip creates a new appointment in MS Outlook.
Note: you will need to provide a time in Date variable [MyDate] else it will
be scheduled at 0:00:00
Superfluous: replace [MyDate] by your own variable or (document)object
value.
Set a reference to the Outlook library in VBE, run below code and open
Outlook to check.

Dim ol As New Outlook.Application
Dim ci As AppointmentItem
Set ci = ol.CreateItem(olAppointmentItem)
ci.Start = MyDate
ci.Subject = "New presentation"
ci.Location = "The Auditorium"
ci.Save
ol.Quit
Set ol = Nothing

Krgrds,
Perry
 
G

gary.cassidy

Cool! I'll have a peek at the code and see how to adjust my current
routine to add it. I have a text box that users currently employ to
enter the appointment time. I'll have a look at what else could be
employed to prevent problems with data entry.

Thanks very much for the help!

Gary
 
G

gary.cassidy

Perry

I've been looking through the help files at the "start" command. I'm
not finding any instructions on how to combine the date & time in the
ci.Start.

I've checked the CreateItem help as well but again see no explanation
as to how they get combined.

I'd appreciate further direction.

Thanks

G
 
G

gary.cassidy

Hmm, the server tells me it failed to post my follow up to my follow up
(smile). Hopefully, we won't get a double posting....

I didn't want it to appear that I've done no work of my own. I've
checked the help files (in Outlook & Word VBA) for direction on adding
the time to the date.

I have had no success in looking up CreateItem, AppointmentItem,
Appointment, Start, StartTime. What am I missing?

Thanks

G
 
G

gary.cassidy

Perry,

I realized mysecond question is poorly worded. Let me show you what I
have done so it doesn't look like I'm asking you to do everything.

I took your initial code and only made a simple change to it like this

Dim ol As New Outlook.Application
Dim ci As AppointmentItem
Set ci = ol.CreateItem(olAppointmentItem)
ci.Start = datOutlookDate
ci.Subject = strClientName & " " & strClientSurname & " PA Review"
ci.Location = "Workstation"
ci.Save
'ol.Quit
Set ol = Nothing

The datOutlookDate is simply the "value" property of the calendar.
Running the code does exactly as you stated it would; it sets an
appointment for 0:00:00. Where I'm lost is in how to add to that, the
user's specific time.

The help files for CreateItem, Start, AppointmentItem & StartTime don't
point me anywhere. What am I missing?

Thanks
 
P

Perry

Look at how you can concatenate 2 string variables into a valid dateformat.
It's your move to engage this approach (or one of yr own design) into a
suitable inputmechanism in Word....
Good luck!

Dim sDate As String
Dim sTime As String
Dim datOutlookDate As Date

sDate = "12/30/2005"
sTime = "01:15:00 PM"

datOutlookDate = CDate(sDate & " " & sTime)
 

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

Top