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

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
what does this do

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

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
Your problem is, as I understand it with this line

Set objRecip = objNS.CreateRecipient(strName)
OR
Set objRecip = objNS.CreateRecipient("myemailaddress@email.com")

You need to try a proper email address of someone, try you own. Further test if objRecip is an object of if it is Nothing. Further then to make sure that exchange is up with you code the Resolve just makes sure that exchange recognises the email address. It should return TRUE.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
Having looking around the code I have noticed that is line

Set objRecip = objNS.CreateRecipient(strName)

after hitting F8 past it it still come up with the following when I put the mouse over it.

objRecip - strName""

objNS.CreateRecipient(strName) - strName""

Am I right in thinking this isn't right and it should be showing mine and someone else email address?
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
strName is a variable = you must either make that variable = to a proper email address OR you need to put

Set objRecip = objNS.CreateRecipient("myemail@enail.com")

The first option allows you to code this with flexibility and change whose email you use.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
So using the first option:

Set objRecip = objNS.CreateRecipient(strName)

strName should be picked up by this bit thats in the code?:

strName = Me.Text28
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
yes provided that Me.Text28 is a control on your form that contains a properly formatted email address.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
right cool and yes it's a email address.

so back to earlyer post, so should the following line when I hover mouse over the code show the email thats in that text box? because it doesn't

Set objRecip = objNS.CreateRecipient(strName)
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
That is impossible.

Code:
strName = Me.Text28
Set objRecip = objNS.CreateRecipient(strName)

If you put your mouse over strName and Me.Text28 and it is an email address then strName on the next line must be the same.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
yeah your right it's impossible, it is there.

still having problems with this line:

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)


Plus I'm now getting a runtime error 91 "Object variable or With block variable not set, on these lines

.Start = Me!AbsenceDateFrom
.End = Me!AbsenceDateTo
.Subject = Me!Subject
If Not IsNull(Me!AbsenceNotes) Then .Body = Me!AbsenceNotes

But when I hover the mouse over each one they do have values.
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
woooo slow down. You are missing some steps out. Your error message means that your appointmentitem object is not working. So is objFolder returning an object? If not then with whos email address are you trying this with? Try it with your own.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
objFolder is returning with Nothing.

I'm using my email
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
Ok assuming you have a recipient object then it might not work with your own email address. You then need to get someone to share their calendar with you and for them to give you read AND write rights. Then you use their email address.
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
show your code from the point of getting the namespace to when you start to use your appointment object please.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
Set objRecip = objNS.CreateRecipient(strName)
If Not objRecip.Resolve Then
On Error Resume Next
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
strName = Me.Text28
.Start = Me!AbsenceDateFrom
.End = Me!AbsenceDateTo
.Subject = Me!Subject
If Not IsNull(Me!AbsenceNotes) Then .Body = Me!AbsenceNotes
.BusyStatus = olOutOfOffice
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
I know that "On Error Resume Next" is in my code somewhere but please understand what it means before using it. It basically means that it will skip through code without showing certain error messages.


Code:
Set objRecip = objNS.CreateRecipient(strName)
If objRecip is Nothing then
    MsgBox "You do not have a recipient"
    Exit Sub
end if
If Not objRecip.Resolve Then
    MsgBox "You have not given a proper email address"
    Exit Sub
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
If Not objFolder Is Nothing Then
     Set objAppt = objFolder.Items.add
else
   Msgbox "You do not have the right to view this persons calendar"
   Exit Sub
end if
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
Here's a funny one for you.

I used the code you just sent and it worked lovely, but when I went to use it again I'm getting a error again on this line:

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)


Plus strName is now not getting poppulated
 

darbid

Registered User.
Local time
Today, 15:09
Joined
Jun 26, 2008
Messages
1,428
Here's a funny one for you.

I used the code you just sent and it worked lovely, but when I went to use it again I'm getting a error again on this line:

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
I have no idea why. Outlook does not having leaks or objects which are not properly cleaned up. It is one of the few MSOffice / VBA things that is not so forgiving. I thus guess that in your testing you are setting outlook objects and then not cleaning them up.

While testing, if you get an error I would suggest that you close your access program totally and close Outlook too. Then check to make sure it all is closed and not still running in Task manager.

The code solution once you get it right is to set all Outlook objects to nothing and make sure you leave the Outlook.Application till last.


Plus strName is now not getting poppulated
That is up to you to find out. Most likely your field on your form is not correct.
 

whybrow23

Registered User.
Local time
Today, 14:09
Joined
May 20, 2011
Messages
38
Think I've found the problem, in the code the line:

Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)

is before this line

strName = Me.Text28

and from this line everything else get the email address from, so because it's after the objFolder it's bringing up the runtime error. am I right?
 

Users who are viewing this thread

Top Bottom