Solved

VB6 - Issue to send the calandar event to required attendees Microsoft Outlook

Posted on 2014-07-25
16
144 Views
Last Modified: 2014-08-07
Hi

I'm having a problem with the below code.

This code will create a Microsoft Outlook event and all add required attendees.

The issue I'm getting is that it does not send to attendees at all, unless i open the calendar event after and then, click send.

I really want to send it right away without having to re open the even.

How can i do that?

Thanks

 Dim objApp As Outlook.Application
                                Dim objNS As Outlook.Namespace
                                Dim objFolder As Outlook.MAPIFolder
                                Dim objDummy As Outlook.MailItem
                                Dim objRecip As Outlook.Recipient
                                Dim objAppt As Outlook.AppointmentItem
                                Dim strMsg As String
                                Dim strName As String
                                On Error Resume Next

                                ' ### name of person whose Calendar you want to use ###
                               
                                strName = "email.address"

                                Set objApp = CreateObject("Outlook.Application")
                                Set objNS = objApp.GetNamespace("MAPI")
                                Set objDummy = objApp.CreateItem(olMailItem)
                                Set objRecip = objDummy.Recipients.Add(strName)
                                objRecip.Resolve
                                If objRecip.Resolved Then
                                    On Error Resume Next
                                    Set objFolder = _
                                    objNS.GetSharedDefaultFolder(objRecip, _
                                                                 olFolderCalendar)
                                    If Not objFolder Is Nothing Then
                                        Set objAppt = objFolder.Items.Add
                                        If Not objAppt Is Nothing Then
                                            With objAppt
                                            .RequiredAttendees = "email.address;email.address"
                                                .Subject = "Store flip "
                                                .Start = year1 & "/" & month1 & "/" & day1
                                                .AllDayEvent = True
                                                .Body = "Please create in new store location" 
                                                .BusyStatus = olBusy
                                                .Send
                                                .Save
                                            End With
                                        End If
                                    End If
                                Else
                                    MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
                                           "User not found"
                                End If

                                Set objApp = Nothing
                                Set objNS = Nothing
                                Set objFolder = Nothing
                                Set objDummy = Nothing
                                Set objRecip = Nothing
                                Set objAppt = Nothing

Open in new window

0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
16 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40219339
Before you set it to nothing
objDummy .Send
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40219619
On row 35, i do have .Send

do i need to set that 2 times?
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40219671
ahh no, first remove your on error resume next, to see what is happening.  You may be getting an error and may not know it.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 11

Author Comment

by:Wilder1626
ID: 40219797
I have removed the ON ERROR RESUME NEXT. I don't have any errors.

i may add that the attendees are network users only and i'm on Lync also. I dont know if this can change something in the config.
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40219865
You had 2 on error resume next, did you remove both?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40219973
Yes, both are removed and no error happen
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40220007
I have a feeling that the application is exiting too soon and does not have a chance to be sent. Move your objects outside your function (declare globally) and place a timer on the form that waits xx seconds before setting the objects to null
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40220074
if i put a sleep time in between, should this work normally?

I dont see any change in the result.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 Else
                                    MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
                                           "User not found"
                                End If
                            

                                'Timer1
                                Sleep 50000
                                
                                Set objApp = Nothing
                                Set objNS = Nothing
                                Set objFolder = Nothing
                                Set objDummy = Nothing
                                Set objRecip = Nothing
                                Set objAppt = Nothing

                            End If

Open in new window

0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40220378
sleep isn't going to relinquish control back to the program.  That's why you set a timer after the function then n the timer trigger close the items.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40220452
i just tried that but still the same result.

How would you set the timer?

Just like this?
    Set objApp = Nothing
    Set objNS = Nothing
    Set objFolder = Nothing
    Set objDummy = Nothing
    Set objRecip = Nothing
    Set objAppt = Nothing

Open in new window

0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40220516
List the contents of this entire sub routine
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40221352
Hi Randy

even if i put the entire sub routine in the timer, i still have the same result.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40221861
After some other tests, still not a good result.

is it possible to run the script but when it will be the time to send, it will let me do it manually bu clicking on the send button?


.RequiredAttendees = "email.address;email.address"
                                                .Subject = "Store flip "
                                                .Start = year1 & "/" & month1 & "/" & day1
                                                .AllDayEvent = True
                                                .Body = "Please create in new store location" 
                                                .BusyStatus = olBusy

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40222546
i found it. i need to use .Display.

I will do some test
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40223182
i still have the same issue

but i think i know why, but cannot see how to fix this.

when the calendar app display, if i click inside the RequiredAttendees field, it validate the name. then, it send the appointment. But if i dont select the attendees field, it does not work. Probably because it does not recognize the email address.

would you know why?
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 40246536
Hi Randy

this is working now. Thanks a lot for your help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question