Outlook contact problem

  • Thread starter Thread starter Robgould
  • Start date Start date
R

Robgould

Guest
Hello,

I have some code to add a contact to outlook from my database. It works well as long as outlook is running. I outlook is closed it does not add, but after I start outlook and click my button again, it adds twice. I am not quite sure what is happening. Any suggestions would be apppreciated. Thanks.

Here is the code:

Code:
Private Sub Command261_Click()


Dim olApp As Outlook.Application
Dim olnamespace As Outlook.NameSpace
Dim objcontact As Outlook.ContactItem

  
        Set olApp = New Outlook.Application
        Set olnamespace = olApp.GetNamespace("MAPI")
        Set objcontact = olApp.CreateItem(olContactItem)
        
       With objcontact
          .LastName = Me.LastName
          .Save
       End With
       Set objcontact = Nothing
       Set objOutlook = Nothing
End Sub
 
I am not 100% sure, but in order for you to update your contacts Outlook must be running.

I think this because my IPOD video has an option to have my outlook contacts loaded. If outlook is not running I get an error message.


Hope this helps...
 
I suspect that what is happening here is that your code correctly opens Outlook and adds your new contact but doesn't close close it. Outlook is still running in the background, even though you can't see it.

When you open Outlook manually, this is a different instance of the app from the one you opened in code. You then run your code again and Outlook then shows you both instances of your new contact (I think???)

Try closing Outlook in your code and see what happens then.
 
This works...

http://www.utteraccess.com/forums/showflat.php?Cat=&Number=1080200

It probably worked befor, but not sure. When I first tried the new code I did not think it worked either. So while I sat there thinking outlook must have updated and then there was my contact. It did not add right away. Took about 20-30 seconds after I opened outlook before it showed up. If you use the same code while outlook is already open it updated immediately. So there is that. Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom