How to write form data to calendar entry

T

Trent Shirley

Can anyone give me sample code of taking data from a custom form and writing
it to a calendar entry in Outlook?

I am new to Outlook forms programming but given an example I can figure it
out. Starting from scratch never have seen it done and having outdated
reference material is bringing me down. :)

Thanks
 
S

Sriram N A

You could always simply copy the field values using event code in your
custom form:

Const olAppointmentItem = 1

Set objAppt = _
Application.CreateItem(olAppointmentItem)
With objAppt
.Start = dteStart
.End = dteEnd
'etc.: dteStart, dteEnd etc. are your Custom Form variables
.Save
End With
 
T

Trent Shirley

Yes, this does work well for me.
Thank you very much.

Can you tell me the method of how to direct the output to a custom form
rather than the standard calendar form?
We have an alternative calendar form that has an extra tab of data that I
need to fill also. I do not want to open the other form, just use it as the
object to be filled in the calendar.

The problem is that we have one form that launches another form. The second
form creates the calendar entry and writes data out to a database.
Once the user returns to the original form though trying to exit that form
causes outlook to crash. I have not been able to find a solution to that
problem up to and including talking with Microsoft support. My alternative
is to migrate the functions of the second form into the form that calls it
and it seems to be going well. I just have to take the output and send it
to a custom rather than the default calendar form and everything is fine.
:)

This has been a very trying problem so far and all of my previous messages
asking about what might be causing outlook to crash went unanswered so I
gave up that approach.
 
S

Sriram N A

AFAIK, you'd be better off trying to fix whatever problem is caused by the
second form, since you have the benefit of the automatic copy of form data
(including all custom fields), with no extra coding. Troubleshooting would
involve making sure all recordsets and connections are closed, and maybe
have the second form close itself discarding all changes after doing the
database write.

Otherwise, I guess you'd create an instance of the new form with
Set objItem = objFolder.Items.Add(strMsgClass)

and set the data values with
objItem.Userproperties("myCustomField").Value = whatever

I don't quite follow what you mean by "not opening the second form". You
can avoid that only if you programmatically change the message class of the
saved calendar entry.

Trent said:
Yes, this does work well for me.
Thank you very much.
 
T

Trent Shirley

I banged my head on the other problem for a LONG time. I made certain all
connections were closing and that no variable names were the same between
the two different forms and even went as far as forcing the current folder
and form information back to correct information just in case but none of it
made any difference. The person who attempted this fix before me spent
hours on the phone with Microsoft who could not identify what the cause of
the crash was.
Interestingly, when the calendar form accessed an Access 97 database with
DAO.DBEngine.35 it worked perfectly. When we converted the database to
Access 2000 and changed the DAO reference to .36 as needed, the calendar
form still worked correctly but the New Hire form that called it would
crash.

Unfortunately I cannot set the New Hire form to discard changes as it is
part of the workflow that they go into that form, change data then call the
calendar form that updates the database. When they exit the New Hire form
it has to save the changes or they end up having to go in and modify the
data twice.

What I am attempting now is to incorporate all the functions from the custom
appointment form directly into a page on the New Hire form so that no call
to an external form is needed. It should be relatively straightforward. I
already have set it up so that it can create the calendar entries by
pressing a button in the New Hire form. It currently is using the default
appointment form though so all of the additional form field data from the
custom form is lost. I have figured out how to specify the form to use but
am still trying to figure out how to pass the custom values into the custom
form. I will puzzle it out through trial and error eventually.
I have it writing the normal fields correctly like Subject, Categories,
Location, Start Time, End Time, etc. I just have not yet had success
passing over the the custom data like cost center info, contact info,
division name, project number, etc.
I have been scouting for sample code that passes custom fields to a custom
appointment form.
I have little experience with Outlook forms but I can read and adapt sample
code pretty well.

Once I figure out the little hangup with these custom fields and I am
CERTAIN it is a simple error on my part, then I will have it all working.

Right now I am using something like this.
Set NewEntry =TheseItems.Add("IPM.Appointment.MAC Calendar Entry") (Where
TheseItems is the path to the folder)
NewEntry.Subject = strSubject
NewEntry.Location = strLocation
........
For the custom fields I am trying this.
NewEntry.userproperties("txtProjNumber") = ProjNum

I am not certain if txtProjNumber above would refer to the display name or
the field name of the field I want to insert the data into in the
appointment form. ProjNum is the value that I want to insert.
I have tried this in several different variations and all have failed so it
could be the syntax is incorrect. I just do not know enough about it and
have no reference material except what I can find on the web.
 
S

Sriram N A

Trent Shirley said:
Unfortunately I cannot set the New Hire form to discard changes as it is
part of the workflow that they go into that form, change data then call the
calendar form that updates the database. When they exit the New Hire form
it has to save the changes or they end up having to go in and modify the
data twice.

Well, what I meant by discarding changes was a two-step process:
- Save the second form at the outset,
- Write out to the database,
- Close the second form, specifying that all changes
if any since the last save are discarded.

This should address any "side effects" of the form code used to do the
database stuff.
For the custom fields I am trying this.
NewEntry.userproperties("txtProjNumber") = ProjNum

I'm almost certain you're referring to the name of the form control rather
than the field name, which are two entirely different animals. This won't
work. You need to use the field name, as displayed in the Field Chooser.
 

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