Creating an appointment in outlook shared calendar using an access form (1 Viewer)

Docko

Registered User.
Local time
Today, 03:14
Joined
May 6, 2011
Messages
13
I get

run-time error '438' object doesnt support this object or method

This is from the line

strName = Me!Assigned_to.Value
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
Pretty close, the line that is the problem is the next one where do you set a reference to your Outlook object "objApp" - you need this at the beginning to get MAPI.
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
also can you check to make sure you are getting your recipient properly something like this

Code:
if not objRecip.Resolve then
       msgbox "We have a problem"
end if
 

Docko

Registered User.
Local time
Today, 03:14
Joined
May 6, 2011
Messages
13
Could you show me an example i dont quite get it!

Thank you
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
have a look at your first post, you have used it there CreateObject("outlook.application")
 

Docko

Registered User.
Local time
Today, 03:14
Joined
May 6, 2011
Messages
13
Hi Darbid,

I've put that in as below but i now get "run-time error '2147467259 (80004005)' the operation failed"

It highlights this line: Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)


Private Sub AddAppt_Click()
Dim objNS As outlook.NameSpace
Dim objFolder As outlook.MAPIFolder 'get name of other persons folder
Dim objRecip As outlook.Recipient 'other persons name
Dim strName As String 'the name or email of the persons folder
Dim objAppt As outlook.AppointmentItem
Dim objApp As outlook.Application

'This example assume that the Outlook object is already alive.
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName)
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
' ### name of person whose Calendar you want to use ###
strName = Me!Label22.Value
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.Add

If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If

If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If

Else
MsgBox "no access to the folder meaning it is not shared"
End If


With objAppt
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
.Subject = Me!Appt
.MeetingStatus = olMeeting
If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = _
Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
.BusyStatus = olBusy

.Save

.Display
End If


End With



Set objNS = Nothing
Set objFolder = Nothing
Set objRecip = Nothing
Set objApp = Nothing
End Sub
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
strName = Me!Label22.Value is in the wrong place - you use it before it has a value.
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If

should also be after you set objRecip

But this will not cause an error it will just help to understand.
 

Docko

Registered User.
Local time
Today, 03:14
Joined
May 6, 2011
Messages
13
Morning Darbid,

I hope you are well. I've tried what you have suggested and now i get

Run-time error '91': Object variable or with block variable not set

It highlights this line "Set objNS = objApp.GetNamespace("MAPI")"

Thanks for your help again!!


Private Sub AddAppt_Click()
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder 'get name of other persons folder
Dim objRecip As Outlook.Recipient 'other persons name
Dim strName As String 'the name or email of the persons folder
Dim objAppt As Outlook.AppointmentItem
Dim objApp As Outlook.Application

'On Error Resume Next
' ### name of person whose Calendar you want to use ###
strName = Me.Assigned_to.Value
'This example assume that the Outlook object is already alive.
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName)
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.Add
If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If


End If


With objAppt
.Start = Format(Me.ApptDate, "Short Date") & " " & Format(Me.ApptTime, "Short Time")
.End = Format(Me.ApptEnd, "Short Date") & " " & Format(Me.ApptEndTime, "Short Time")
.Location = Me.ApptLocation
.Subject = Me.Appt
.MeetingStatus = olMeeting
.ReminderMinutesBeforeStart = 20
.BusyStatus = olBusy
.Recipients.ResolveAll

.Save

.Display



End With



Set objNS = Nothing
Set objFolder = Nothing
Set objRecip = Nothing
Set objApp = Nothing
'dont forget to also set outlook to nothing. Also do the Outlook object last. Outlook will not close properly otherwise.

End Sub
 

whybrow23

Registered User.
Local time
Today, 03:14
Joined
May 20, 2011
Messages
38
Hi Guys

Been playing with this to and have come across a error and was wondering if you could help.

When I press the send to outlook button I get the following run-time error:

Run-time error '-2147352567 (80020009)':

Outlook does not recongnize one or more names.

and this bit of code that is highlighted:

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)

If you need the whole code to help let me know.

Many Thanks
M
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
welcome to the forum. Yes show you full OUTLOOK code.
 

whybrow23

Registered User.
Local time
Today, 03:14
Joined
May 20, 2011
Messages
38
Hi there and thank you.

Heres the code:

Private Sub AddAppt_Click()
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder 'get name of other persons folder
Dim objRecip As Outlook.Recipient 'other persons name
Dim strName As String 'the name or email of the persons folder
Dim objAppt As Outlook.AppointmentItem
Dim objApp As Outlook.Application
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
'On Error Resume Next
' ### name of person whose Calendar you want to use ###
'This example assume that the Outlook object is already alive.
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName)
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.add
If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If

End If
With outappt
'strName = Me.Who.Value
.Start = Me!ApptDateFrom
.Duration = Me!ApptDateTo
.Subject = Me!Appt
If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = _
Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
.BusyStatus = olOutOfOffice
End If
.Save
End With
Set objNS = Nothing
Set objFolder = Nothing
Set objRecip = Nothing
Set objApp = Nothing
'dont forget to also set outlook to nothing. Also do the Outlook object last. Outlook will not close properly otherwise.
End Sub
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
I see the copy and paste monster has bitten you. It is Friday, go out tonight and have a few beers, then get a big knife and cut off the fingers that you use to copy and paste, then drink until the words "copy" and "past" drown in beer and die. Or find the men in black.

Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)

why do you set outlook twice? Also it is too early to set an appointment yet


Set objAppt = objFolder.Items.add
If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If

With outappt

your Outlook appointment item if it works will be objAppt so it is to this you will make your appointment. not outappt.
 

whybrow23

Registered User.
Local time
Today, 03:14
Joined
May 20, 2011
Messages
38
Morning

Yes your right the monster has bitten me, but my problems is I'm a novice, I know what I want it to do but not how to make it do it. :)

So..... I don't have a clue
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
No problem. So if you understood my last post take out the things I have talked about above. Then (even if you did not understand) put in a breakpoint right at the beginning of this code and step through it with F8. Before each step put your mouse over variables and objects like objAppt and you will get a popup of its value or if it is an object of null. If it is null or the wrong value then you know there is a problem.

For example you have this line

Code:
Set objRecip = objNS.CreateRecipient(strName)
Before this is executed put your mouse over strName. Does an email address pop up? Then hit F8 and after it has executed, now when you put your mouse over objRecip do you see object or null.

If you see null it might not error but
Code:
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
will error because it needs objRecip to be something.

Once you know your problem you might be able to solve it your self, otherwise just write back here on the specific line that is causing you a problem and I will help you.
 

whybrow23

Registered User.
Local time
Today, 03:14
Joined
May 20, 2011
Messages
38
I think I've made the changes you said about. I've also highlighted the lines and what i'm getting on them when putting mouse over it. see code below


Private Sub AddAppt_Click()
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder 'get name of other persons folder
Dim objRecip As Outlook.Recipient 'other persons name
Dim strName As String 'the name or email of the persons folder
Dim objAppt As Outlook.AppointmentItem
Dim objApp As Outlook.Application
Dim outobj As Outlook.Application
Set outobj = CreateObject("outlook.application")
'On Error Resume Next
' ### name of person whose Calendar you want to use ###
'This example assume that the Outlook object is already alive.
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName) - objrecip = "" - strname = ""
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar) objFloder = Nothing - objRecip = "" - olFlowderCalendar = 9
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.add
If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If

End If
With objAppt
strName = Me.Who.Value
.Start = Me!ApptDateFrom
.End = Me!ApptDateTo
.Subject = Me!Appt
If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = _
Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
.BusyStatus = olOutOfOffice
End If
.Save
End With
 

darbid

Registered User.
Local time
Today, 04:14
Joined
Jun 26, 2008
Messages
1,428
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName) - objrecip = "" - strname = ""
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar) objFloder = Nothing - objRecip = "" - olFlowderCalendar = 9

Ok your first problem is you need a recipient. You need this because it is from HIS folder that you are going to make an appointment. Thus to get him you need his email address. strName = "donanl.duck@disney.com" or strName = Me.emailField.Value.

This may solve your second problem. If it does not you need to check if you have rights to make appointment for the person. Try it manually first.
 

whybrow23

Registered User.
Local time
Today, 03:14
Joined
May 20, 2011
Messages
38
Good morning

Right strName now picks up the email address but I'm still getting a error on this line.

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)

I've put mouse over each one and I get the following

objFolder - Nothing

objRecip - ""

olFolderCalendar - 9

I have tried it to someone else's calendar I have permission to and also my own, and still get this error.
 

Users who are viewing this thread

Top Bottom