Welcome, Guest
Guest Settings
Help

Thread: Outlook calendar: multiple accounts. How to choose the account by code ?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0 Threads: [ Previous | Next ]
roberto nicchi

Posts: 77
Registered: 4/11/01
Outlook calendar: multiple accounts. How to choose the account by code ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 3:18 AM
Hello. I use the function below to create events in Outlook calendar. Outlook is connected to an Exchange server (Office 365)
The Outlook client has multiple calendar accounts. Is it possible to choose, by code, the account where the event is saved ?

thanks

Roberto

function CreateNewAppointment(Subject,Location,body:string;start_date,end_date:TDate;start_time,end_time:TTime;allday:boolean;var EntryId:OLEVariant):shortint;
var
outlook, ns, folder, appointment:OLEVariant;
begin
// result=0 ok
// result>1 error
try
outlook := CreateOLEObject('Outlook.Application');
except
result:=1;
exit;
end;
try
try
ns := outlook.GetNamespace('MAPI');
except
result:=2;
exit;
end;
try
folder := GetCalendarFolder(ns.Folders);
try
if not VarIsNull(folder) and not VarIsEmpty(folder) then
begin
appointment := folder.Items.Add(olAppointmentItem);

appointment.Subject := Subject;
appointment.Body := Body;

if not(Location='') then
appointment.Location := Location;

if start_time>0 then
appointment.Start := start_date+start_time
else appointment.Start := start_date;

if ((end_date>start_date) or (end_time>start_time)) then
begin
if end_time>0 then
appointment.End := end_date+end_time
else
appointment.End := end_date;
end;

if allday then
appointment.AllDayEvent := 1 {all day event}
else
appointment.AllDayEvent := 0;

appointment.ReminderMinutesBeforeStart := 0;
appointment.ReminderSet := 1;

appointment.Importance := olImportanceHigh;

appointment.Save;

entryid:=appointment.entryid;

result:=0;
end
else result:=3;
finally
folder := UnAssigned;
end;
finally
ns := UnAssigned;
end;
finally
outlook := UnAssigned
end;
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02