Select Names Dialog Box

J

jo

Could someone help with the following?

I am using Access 2003 with outlook 2003 and all I need to do is open
outlook and for it to display the Select Names Dialog Box ( it would be nice
to open outlook if it was closed) no more than that. Hence I am now after
the code to go in the click event of the button.

Any examples of VBA code that will work within Access 2003 would be
appreciated
 
J

jo

Thank you Jp for the info.
In view of your reply, I have seen code being used (VB) for the display of
the address book.
Have you used or knowledge of any outlook VBA address book code examples?

I will post a message in this group on this subject.

Thank you again
 
J

JP

I don't doubt that you've seen code that displays the address book,
but Outlook doesn't provide any means of doing so prior to Outlook
2007. I have seen (and used) VBA code that manipulates contacts, but
not in the way you want. If you can show otherwise, I'd be glad to see
it.

--JP
 
K

Ken Slovak - [MVP - Outlook]

Of course in the old days we used to use CDO.Session.AddressBook() to
display that dialog before the OOM exposed it.




I don't doubt that you've seen code that displays the address book,
but Outlook doesn't provide any means of doing so prior to Outlook
2007. I have seen (and used) VBA code that manipulates contacts, but
not in the way you want. If you can show otherwise, I'd be glad to see
it.

--JP
 
J

jo

Hi, Ken
Is it possible to get the example working in the environment I need?
If so your help would be appreciated
Regards
Dave
 
K

Ken Slovak - [MVP - Outlook]

That thread you referenced has code for that.

CDO is an optional installation for Office 2003 and earlier so you may not
have it installed, you have to check that. CDO also is subject to very
strict security, even stricter than the Outlook object model, so you also
have to be aware of that. Most of us stopped using CDO years ago because of
that, that's one of the reasons that Redemption (www.dimastr.com/redemption)
was created.
 
J

jo

Hi, Ken
I am using the following code that basicly works, other than if outlook is
closed.
hence what code is required to open outlook if it is closed?
It also looks like .AddressBook has a number of options. Could you list or
point me to more information on the use of this command.

On Error GoTo err_Session_AddressBook
'MAPI Session
Dim objSession As MAPI.Session
Dim colCDORecips As Object

Set objSession = New MAPI.Session
'objSession.Logon "ProfileName", "outlook", False, False
objSession.Logon , , False, False
'show address book
Set colCDORecips = objSession.AddressBook(, _
"Pick Names", , , 1, _
"Recipients")
' release objects
objSession.Logoff

Set colCDORecips = Nothing
Set objSession = Nothing


err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
'MsgBox "Unrecoverable Error:" & Err
End If

Thank you

Dave
 
K

Ken Slovak - [MVP - Outlook]

objSession.Logon , , False, False

That's what's called in CDO as a piggy-back logon, attaching to an existing
Outlook session. It would only work if Outlook is already running. An
alternative of specifying a CDO logon profile is usually not the best idea,
it ends up either leaking or creating profiles in your registry that you
don't really want.

Check for Outlook running and if it's not running then start it to avoid the
problem.

www.cdolive.com is the the Web site for CDO. The tips and tricks pages have
lots of code samples and you can download the CDO.HLP file from there which
explains all the arguments to everything in CDO.
 
J

jo

Ken,
I have updated my code as below, it works how I need it to. However could
you have a look at it as I do not full understand you comment on the
objSession.Logon , , False, False.
also I did have a look at the www.cdolive.com site but the sites search
does not work and the copy of the CDO.HLP I can't read at the moment hence
I will have to revisit when I have a bit more time next week.
I take it that if I make a reference to CDO.dll and in my case have an
access database in a folder with the DLL the outlook code I am using will
work on any PC that uses the access programme?


Private Sub Command43_Click()
On Error GoTo err_Session_AddressBook

Dim objOL As Outlook.Application
Dim oOutlook As Object
Dim oMail As Object
Dim objSession As MAPI.Session
Dim colCDORecips As Object

On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(olMailItem)
oMail.Display

End If

Set objSession = New MAPI.Session
objSession.Logon "ProfileName", "outlook", False, False

Set colCDORecips = objSession.AddressBook(, _
"Pick Names", , , 1, _
"Recipients")
' release objects

objSession.Logoff

Set colCDORecips = Nothing
Set objSession = Nothing
Set objOL = Nothing
Set oOutlook = Nothing
Set oMail = Nothing

err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
'MsgBox "Unrecoverable Error:" & Err
End If
End Sub

Thank you for you time and comments.
 
K

Ken Slovak - [MVP - Outlook]

If you're starting Outlook, as I recommended, then you should go back to the
original CDO logon, but modified a little:

objSession.Logon "", "", False, False

If you want that code to run on other machines they will need to have CDO
installed on them. You are not allowed to deploy or distribute CDO yourself,
that's illegal. Plus each version of CDO is customized to a specific version
of Outlook.

We also do not recommend deploying Outlook VBA macro code. That's for
personal use or prototyping, not for distribution. For deployment you should
be coding a COM addin.
 
J

jo

Thank you for the updated logon syntax.
All target PC have CDO installed so no problem with DLL now.
One final issue regarding the address book "show names from the".. drop
down.
How do I change the default location via code, eg at the moment its default
is "contacts" should I need its default to be say "outlook address book"
 
K

Ken Slovak - [MVP - Outlook]

That's stored in the registry in the profile settings, it's all undocumented
binary and Unicode stuff there. It's something that Outlook reads on startup
only. You can't do much with that with a running session.
 

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