Select Names Dialog Box

Status
Not open for further replies.
J

jo@jo.uk

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

JP

The Select Names dialog box is programmable starting from Outlook

2007. You can't display it in Outlook 2003.

http://msdn.microsoft.com/en-us/library/bb176400.aspx

--JP

On Feb 5, 3:52 pm, j...@jo.uk wrote:
> 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@jo.uk

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

On Feb 9, 12:32 pm, j...@jo.uk wrote:
> 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
 
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.

"JP" <jp2112@earthlink.net> wrote in message

news:835aa6f7-4330-45a3-aa90-cf301fb69e93@c5g2000vbh.googlegroups.com...

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

On Feb 9, 12:32 pm, j...@jo.uk wrote:
> 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

jo@jo.uk

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.

<jo@jo.uk> wrote in message

news:Or-dnVlPGYNHsunWnZ2dnUVZ7rqdnZ2d@giganews.com...
> Hi, Ken
> Is it possible to get the example working in the environment I need?
> If so your help would be appreciated
> Regards
> Dave
 
J

jo@jo.uk

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.

<jo@jo.uk> wrote in message

news:x_ydnSnOUvQrBujWnZ2dnUVZ8v2dnZ2d@giganews.com...
> 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
 
J

jo@jo.uk

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.

<jo@jo.uk> wrote in message

news:t82dndxeZo8kd-vWnZ2dnUVZ7sWdnZ2d@giganews.com...
> 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.
 
J

jo@jo.uk

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.

<jo@jo.uk> wrote in message

news:HeCdnTnsLJuoZefWnZ2dnUVZ8mCdnZ2d@giganews.com...
> 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"
 
J

JP

Thanks Ken. Some days, it seems like I open my mouth just to switch

feet.

--JP

On Feb 10, 1:21 pm, "
<kenslo...@mvps.org> wrote:
> Of course in the old days we used to use CDO.Session.AddressBook() to
> display that dialog before the OOM exposed it.

> >

> http://www.slovaktech.com

> "JP" <jp2...@earthlink.net> wrote in message

> news:835aa6f7-4330-45a3-aa90-cf301fb69e93@c5g2000vbh.googlegroups.com...
> 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.
>
 
Status
Not open for further replies.
Top