Access - Outlook - Public Folder - Appointment

G

Guest

Hello,

I have written an Function:

Public Function MakeAppointment(strOutlookFolderID As String, strSubject As
String, datDatum As Date, strLocation As String, strBody As String, bolAllDay
As Boolean, Optional strvon As String, Optional strbis As String, Optional
strOutlook As String) As String
5 On Error GoTo Handler
Dim olfolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim olns As Outlook.NameSpace

10 Set olApp = CreateObject("Outlook.Application")
15 Set olfolder =
olApp.GetNamespace("MAPI").GetFolderFromID(strOutlookFolderID)

20 If Nz(strOutlook) = "" Then
25 Set objAppt = olfolder.Items.Add
30 Else
35 Set olns = olApp.GetNamespace("MAPI")
40 Set objAppt = olns.GetItemFromID(strOutlook, olfolder.StoreID)
45 End If

50 With objAppt
55 .Subject = strSubject
60 If Nz(Trim(strLocation)) <> "" Then
65 .Location = strLocation
70 End If
75 If bolAllDay = False Then
80 .start = CDate(datDatum & " " & strvon & ":00")
85 .End = CDate(datDatum & " " & strbis & ":00")
90 .AllDayEvent = False
95 Else
100 .start = datDatum
105 .AllDayEvent = True
110 End If

115 .ReminderSet = False
120 .Body = strBody
'.Importance = olImportanceHigh
125 .Save
130 MakeAppointment = .EntryID
135 End With

140 Set objAppt = Nothing
145 Set olApp = Nothing
150 Set olfolder = Nothing
155 Set olns = Nothing
160 Exit Function
Handler:
Msgbox Err.number & "|" & Err.Description
End Function



But sometimes and mainly when Outlook not started, I get en Error in line
15? Why?

I hope anyone can help me.

Thank you.
Marius
 
R

Robert Morley

Try separating that line into two lines:

Set olns = olApp.GetNamespace("MAPI")
Set olfolder = olns.GetFolderFromID(strOutlookFolderID)

.... and see which of the two lines is actually the problem. If it's the
olns line, I don't know; if it's the olfolder line, then it's probably
because you've specified an invalid ID.



Rob
 
M

Marius

Hello,

thanks for an answer.

I tried this:

Public Function MakeAppointment(strOutlookFolderID As String, strSubject As
String, datDatum As Date, strLocation As String, strBody As String,
bolAllDay As Boolean, Optional strvon As String, Optional strbis As String,
Optional strOutlook As String) As String
5 On Error GoTo Handler
Dim olfolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim olns As Outlook.NameSpace
Dim myStoreID As String


10 Set olApp = CreateObject("Outlook.Application")
15 Set olns = olApp.GetNamespace("MAPI")
20 olns.Logon , , False, False
25 Set olfolder = olns.GetFolderFromID(strOutlookFolderID)

30 If Nz(strOutlook) = "" Then
35 Set objAppt = olfolder.Items.Add
40 Else
45 myStoreID = olfolder.StoreID
50 Set objAppt = olns.GetItemFromID(strOutlook, myStoreID)
55 End If

60 With objAppt
65 .Subject = strSubject
70 If Nz(Trim(strLocation)) <> "" Then
75 .Location = strLocation
80 End If
85 If bolAllDay = False Then
90 .start = CDate(datDatum & " " & strvon & ":00")
95 .End = CDate(datDatum & " " & strbis & ":00")
100 .AllDayEvent = False
105 Else
110 .start = datDatum
115 .AllDayEvent = True
120 End If

'recurring appointment
'.IsRecurring

125 .ReminderSet = False
130 .Body = strBody
'.Importance = olImportanceHigh
135 .Save
140 MakeAppointment = .EntryID
145 End With

150 olns.Logoff

155 Set objAppt = Nothing
160 Set olfolder = Nothing
165 Set olns = Nothing
170 Set olApp = Nothing
175 Exit Function
Handler:
Msgbox err.Number & vbnewline & err.Description
End Function

Now I had an error in line 50. I dont know why.
I think the ID is right.

MFG
Marius
 
S

Sylvain Lafontaine

You will have a better chance to get an answer if you ask your question in a
newsgroup about Outlook: even if your VBA code is used inside an ADP
project, clearly your error has nothing to do with ADP.
 
R

Robert Morley

You might have to declare your Appointment object as simply an Object, I'm
not 100% sure. I've never worked with retrieving items by ID, so I don't
know if they can be early-bound, or if they have to be late-bound.

As Sylvain said, you're probably better off finding an Outlook group of some
kind, as there won't be a lot of us here that have significant experience
with all aspects of Outlook.



Good luck,
Rob
 
D

david epsom dot com dot au

BTW,
Msgbox err.Number & vbnewline & err.Description

Since you've got the line numbers,

Msgbox err.Number & vbnewline & err.Description & " at line " & erl

(david)
 

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