Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pre-populate Address Book

11 views
Skip to first unread message

McKilty

unread,
Aug 5, 2014, 3:10:49 PM8/5/14
to
I have a form on which the user can select recipients for TO, CC, and BCC.

My code currently displays the addressbook, lets the user select recipients, and then it takes what they have selected in puts it into one of three fields based on what type they are.

What I would like is for the address book to be pre-populated with what they already have on the form. This is in case they choose recipients, close the address book, and then one to go back to the form and add more.

My code is as follows:

Dim session As RDOSession
Dim ab As RDOAddressBook
Dim recips As RDORecipients
Dim iToCount As Integer
Dim iCcCount As Integer
Dim iBccCount As Integer

Session = CreateObject("Redemption.RDOSession")
Session.Logon()

recips.Add("em...@email.com") <--------------- FAILS

AB = Session.AddressBook
Recips = AB.ShowAddressBook("Choose your Recipients", False, False)

Dim iAddress As Integer
For iAddress = 1 To Recips.Count
Select Case Recips.Item(iAddress).Type
Case 1
iToCount = iToCount + 1
If iToCount > 1 Then
Me.txtTo.Text &= "; "
End If
Me.txtTo.Text &= Recips.Item(iAddress).AddressEntry.SMTPAddress

Case 2
iCCCount = iCCCount + 1
If iCCCount > 1 Then
Me.txtCc.Text &= "; "
End If
Me.txtCc.Text &= Recips.Item(iAddress).AddressEntry.SMTPAddress

Case 3
iBCCCount = iBCCCount + 1
If iBCCCount > 1 Then
Me.txtBcc.Text &= "; "
End If
Me.txtBcc.Text &= Recips.Item(iAddress).AddressEntry.SMTPAddress

End Select
Next



I indicated above where it fails. The error is "Object reference not set to an instance of an object." I have been trying to find a way to get that set or do whatever to make it work.

Thanks!

Norman Peelman

unread,
Aug 5, 2014, 10:19:00 PM8/5/14
to
You have defined the *type* of variable 'recips' is but you haven't
actually created the *object*. Looks like you need a:

Set recips = New RDORecipients

prior to the point of failure. You may need the same for 'ab' as well,
I'm just not in front of my Windows machine to test.


--
Norman
Registered Linux user #461062
AMD64X2 6400+ Ubuntu 10.04 64bit

McKilty

unread,
Aug 6, 2014, 8:08:36 AM8/6/14
to
Thank you for your response.

I've had the line in there before and it gives a different error:

COMException was unhandled

Retrieving the COM class factory for component with CLSID {B32BED47-05E6-402A-9B58-01CA29EA8A83} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).


AB is fine in that if I removed the recips line, everything below it works as expected.

McKilty

unread,
Aug 6, 2014, 9:07:46 AM8/6/14
to
So I decided to research that error and I found that RDORecipients cannot be created as a standalone and needed to be part of a message... I think. The only flaw in this thinking was that I kind of do access recips without an email later in the code.

Anyway, I discovered RDOMail (I had been using other objects that I thought were right) and I got it working. Thanks to all who helped or was going to help ;).

Private Sub cmdSelectRecipients_Click(sender As Object, e As EventArgs) Handles cmdSelectRecipients.Click

Dim session As RDOSession
Dim ab As RDOAddressBook
Dim recips As RDORecipients

Dim iToCount As Integer
Dim iCcCount As Integer
Dim iBccCount As Integer

Dim myMsg As RDOMail

session = CreateObject("Redemption.RDOSession")
session.Logon()

myMsg = session.GetDefaultFolder(rdoDefaultFolders.olFolderOutbox).Items.Add("IPM.Note")
myMsg.Recipients.Add("em...@email.com")

ab = session.AddressBook

recips = ab.ShowAddressBook(myMsg.Recipients, "Choose your Recipients", False, False)



Dim iAddress As Integer
For iAddress = 1 To recips.Count
Select Case recips.Item(iAddress).Type
Case 1
iToCount = iToCount + 1
If iToCount > 1 Then
Me.txtTo.Text &= "; "
End If
Me.txtTo.Text &= recips.Item(iAddress).AddressEntry.SMTPAddress

Case 2
iCcCount = iCcCount + 1
If iCcCount > 1 Then
Me.txtCc.Text &= "; "
End If
Me.txtCc.Text &= recips.Item(iAddress).AddressEntry.SMTPAddress

Case 3
iBccCount = iBccCount + 1
If iBccCount > 1 Then
Me.txtBcc.Text &= "; "
End If
Me.txtBcc.Text &= recips.Item(iAddress).AddressEntry.SMTPAddress

End Select
Next


myMsg = Nothing

End Sub
0 new messages