Create Calendar Appointment with VBScript from Command Button

S

Shaun Simma

I have created a customer journal form with several fields on it. I
use the form to keep a chronological journal of projects that I work
on. As I record my journal activity I have a need to create
appointment items to remind me to followup on various journal entries.

On the form is a command button named "CommandButton1" which is not
bound to any control. I have written the following VBScript to execute
when the button is clicked:

Sub CommandButton1_click()
Dim objOL 'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem
Const olAppointmentItem = 1
Const olMeeting = 1
Const olFree = 0

Set objOL = CreateObject("Outlook.Application")
Set objAppt = objOL.CreateItem(olAppointmentItem)

objAppt.Subject = "My Test Appointment"
objAppt.Start = #8/19/03 3:50:00 PM#
objAppt.Duration = 1
objAppt.Location = "Followup"
objAppt.Body = "Test Verbiage"
objAppt.ReminderMinutesBeforeStart = 1
objAppt.BusyStatus = olFree
objAppt.Save()
Set objAppt = Nothing
Set objOL = Nothing
End Sub

When I click the command button, an appointment item is automatically
added to my calendar. However, I am having difficulting writing the
script to automatically populate the "Start" and "Body" fields on the
appointment form with data from 2 fields on the journal form.

This is what I have done thus far:

(1) Created a text box on my journal form named "txtFollowUpNotes"
which is bound to a custom control named "FollowUpNotes".

(2) Created a text box on my journal form named "txtFollowUpDate"
which is bound to a custom control named "FollowUpDate" with a
"date/time" type.

I need help with writing/adding the appropriate VBSript code to the
code listed above to automatically populate the "Start Time" on the
appointment field with the date that was entered into the
"txtFollowUpDate" field on the journal form; and to automatically
populate the "Notes" area on the appointment field with the text that
was entered into the "txtFollowUpNotes" field on the journal form.

I have played with this script for two days now trying to
programatically get the data into those fields and have had no luck. I
would appreciate assistance from anyone who can provide me with the
modified script/code needed to accomplish my needs outlined above.

Also, with new journal entries do I have to save the entry before
executing the command button?

Thanks in Advance


Shaun Simma
 
S

Shaun Simma

Thanks Ken. Your assistance worked perfectly.

Shaun Simma

Ken Slovak - said:
Outlook forms have intrinsic Item and Application objects, so you
don't need to declare or instantiate your Outlook.Application object.
Just use Application.

If the fields you mention are properties added to the item or to the
folder you can use the following code in the Journal form:

Sub CommandButton1_click()
Dim objAppt 'As Outlook.AppointmentItem
Const olAppointmentItem = 1
Const olMeeting = 1
Const olFree = 0

Set objAppt = Application.CreateItem(olAppointmentItem)

objAppt.Subject = "My Test Appointment"
objAppt.Start = Item.UserProperties.Item("FollowUpDate")
objAppt.Duration = 1
objAppt.Location = "Followup"
objAppt.Body = Item.UserProperties.Item("FollowUpNotes")
objAppt.ReminderMinutesBeforeStart = 1
objAppt.BusyStatus = olFree
objAppt.Save()
Set objAppt = Nothing
Set objOL = Nothing
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Shaun Simma said:
I have created a customer journal form with several fields on it. I
use the form to keep a chronological journal of projects that I work
on. As I record my journal activity I have a need to create
appointment items to remind me to followup on various journal entries.

On the form is a command button named "CommandButton1" which is not
bound to any control. I have written the following VBScript to execute
when the button is clicked:

Sub CommandButton1_click()
Dim objOL 'As Outlook.Application
Dim objAppt 'As Outlook.AppointmentItem
Const olAppointmentItem = 1
Const olMeeting = 1
Const olFree = 0

Set objOL = CreateObject("Outlook.Application")
Set objAppt = objOL.CreateItem(olAppointmentItem)

objAppt.Subject = "My Test Appointment"
objAppt.Start = #8/19/03 3:50:00 PM#
objAppt.Duration = 1
objAppt.Location = "Followup"
objAppt.Body = "Test Verbiage"
objAppt.ReminderMinutesBeforeStart = 1
objAppt.BusyStatus = olFree
objAppt.Save()
Set objAppt = Nothing
Set objOL = Nothing
End Sub

When I click the command button, an appointment item is automatically
added to my calendar. However, I am having difficulting writing the
script to automatically populate the "Start" and "Body" fields on the
appointment form with data from 2 fields on the journal form.

This is what I have done thus far:

(1) Created a text box on my journal form named "txtFollowUpNotes"
which is bound to a custom control named "FollowUpNotes".

(2) Created a text box on my journal form named "txtFollowUpDate"
which is bound to a custom control named "FollowUpDate" with a
"date/time" type.

I need help with writing/adding the appropriate VBSript code to the
code listed above to automatically populate the "Start Time" on the
appointment field with the date that was entered into the
"txtFollowUpDate" field on the journal form; and to automatically
populate the "Notes" area on the appointment field with the text that
was entered into the "txtFollowUpNotes" field on the journal form.

I have played with this script for two days now trying to
programatically get the data into those fields and have had no luck. I
would appreciate assistance from anyone who can provide me with the
modified script/code needed to accomplish my needs outlined above.

Also, with new journal entries do I have to save the entry before
executing the command button?

Thanks in Advance


Shaun Simma
 

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