Discussion:
Pre-populate Address Book
(too old to reply)
McKilty
2014-08-05 19:10:49 UTC
Permalink
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("***@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
2014-08-06 02:19:00 UTC
Permalink
Post by McKilty
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.
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()
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!
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
2014-08-06 12:08:36 UTC
Permalink
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.
Post by McKilty
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.
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()
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!
McKilty
2014-08-06 13:07:46 UTC
Permalink
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("***@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

Loading...