Sub Procedure does not work when perform with different window use

T

TS Lim

I develop a VBA sub procudure. This procedure adds a new contact item to the
default outlook folder. It works fine. But when switch to a different window
user and run the sub procedure again, no new contact item is created. Kindly
advise what are the possile cause of this.

Below is part of my procedure for creating new item in the outlook contact
folder.

Dim ol As Outlook.Application
Dim olns As Outlook.NameSpace
Dim olMAPI As Outlook.MAPIFolder
Dim olCI As Outlook.ContactItem
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set olMAPI = olns.GetDefaultFolder(olFolderContacts)
Set olCI = ol.CreateItem(olContactItem)

olCI.MessageClass = "IPM.Contact"
If Me.LastName <> "" Then olCI.LastName = "ABC"
olCI.Save

Appreciate for your advise.
 
M

Michael Bauer [MVP - Outlook]

Have you copied the same code to the other user's PST file?

BTW: From within VBA you shouldn' start a new root object of the host
application. That is, don't call
Set ol = New Outlook.Application

if you want to use the variable 'ol', use it this way:

Set ol=Application

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Mon, 18 Aug 2008 01:42:00 -0700 schrieb TS Lim:
 
T

TS Lim

I am actually using VBA in Access to automate outlook, to read and write data
into outlook contact item fields from Access Sub Procedure.

The code mentioned is in my Access Sub Procedure, not in the pst file. My
Access program can be accessed in different window users.

I tested the access program in the 1st window user. It runs properly. When I
switch the window to another (2nd) user. The problem menstioned earlier
occured.

In my Access VBA code, which is not shown above, also has reading of data in
the fields of contact item. The reading of data works in both the 1st and 2nd
window users.

Sorry for didnot describe my problem properly earlier.
 
M

Michael Bauer [MVP - Outlook]

Do you know that the default contacts folder for the second user is another
one than for the first user? If you have checked for a new item in the right
folder, you could add any kind of an error handler to the code to see
whether or not an error occurs.

That could look like this:

Sub Whatever()
On Error Goto ERR_HANDLER
' your code
Exit Sub
ERR_HANDLER:
MsgBox Err.Description
End Sub

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 19 Aug 2008 07:44:02 -0700 schrieb TS Lim:
 
T

TS Lim

Dear Michael,

Thank you very much for your advise. I have now solved my problem.

Best regards,
TS Lim
 

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