M
mike_setter
I have a problem with some code that exports from Access97 to Outlook
97 some contact details that are then placed in a Public folder. This
folder is intended to be used as a public available address book
through Exchange 5.5.
Whilst the code does export all the data we need and can be seen in the
public folder by everyone, the problem is that the email address in
Outlook is displayed without any underlining which I assume means it
has not been saved properly. What is more the folder is available as an
Address Book but no contacts are visible within it.
Curiously when I open the created records in my OL97 the only way to
get it to enter it correctly is by amending the email address slightly
and then pressing enter. It then displays with the underline and when I
Save & Close the form it *will* display in the Address Book as well.
When I open the record in OL2K it also does not display the underline
but upon closing the form (without making any changes) it will request
changes to be saved and will update the email address and make it
visible in the address book.
Ultimately I also want to delete the whole folder contents before each
time this procedure is run. I have yet to look at how to do this. Can
someone point me in the right direction.
Am I missing something in my code or is the Outlook code itself at
fault?
My code is displayed below :
Many thanks
Public Function ExportEmailAddresses()
Dim olFldrP As Outlook.MAPIFolder
Dim olFldr As Outlook.MAPIFolder
Dim olNms As Outlook.NameSpace
Dim olOutlookApp As Outlook.Application
Dim olItms As Outlook.Items 'folder items list
Dim olItm As Outlook.ContactItem 'folder item
Dim dbs As Database, rst As Recordset
Dim strTitle As String, strFirstName As String, strLastName As String,
strSuffix As String, strCompany As String
Dim strLastNameFirst As String, strEMailAddress As String, strNickName
As String
Dim lngResult As Long, lngcount As Long, lngPosition As Long
On Error Resume Next
Set olOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set olOutlookApp = CreateObject("Outlook.Application")
End If
Set olNms = olOutlookApp.GetNamespace("MAPI")
Set olFldrP = olNms.Folders("Public Folders")
Set olFldrP = olFldrP.Folders("All Public Folders")
Set olFldr = olFldrP.Folders("Client Email Contacts")
Set olItms = olFldr.Items
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryListEmailableClients", dbOpenSnapshot)
lngcount = rst.RecordCount
For lngPosition = 1 To lngcount
With rst
strTitle = Nz(![prefix])
strFirstName = Nz(![First Name])
strLastName = Nz(![Surname])
strSuffix = Nz(![suffix])
strCompany = Nz(![Company])
strLastNameFirst = Nz(![Surname]) & ", " & Nz(![First Name])
strEMailAddress = Nz(![Email Address])
strNickName = Nz(![dear])
End With
Set olItm = olItms.Add("IPM.Contact")
With olItm
.Title = strTitle
.FirstName = strFirstName
.LastName = strLastName
.CompanyName = strCompany
.suffix = strSuffix
.NickName = strNickName
.Email1Address = strEMailAddress
.Save
.Close (olSave)
End With
rst.MoveNext
Next lngPosition
End Function
97 some contact details that are then placed in a Public folder. This
folder is intended to be used as a public available address book
through Exchange 5.5.
Whilst the code does export all the data we need and can be seen in the
public folder by everyone, the problem is that the email address in
Outlook is displayed without any underlining which I assume means it
has not been saved properly. What is more the folder is available as an
Address Book but no contacts are visible within it.
Curiously when I open the created records in my OL97 the only way to
get it to enter it correctly is by amending the email address slightly
and then pressing enter. It then displays with the underline and when I
Save & Close the form it *will* display in the Address Book as well.
When I open the record in OL2K it also does not display the underline
but upon closing the form (without making any changes) it will request
changes to be saved and will update the email address and make it
visible in the address book.
Ultimately I also want to delete the whole folder contents before each
time this procedure is run. I have yet to look at how to do this. Can
someone point me in the right direction.
Am I missing something in my code or is the Outlook code itself at
fault?
My code is displayed below :
Many thanks
Public Function ExportEmailAddresses()
Dim olFldrP As Outlook.MAPIFolder
Dim olFldr As Outlook.MAPIFolder
Dim olNms As Outlook.NameSpace
Dim olOutlookApp As Outlook.Application
Dim olItms As Outlook.Items 'folder items list
Dim olItm As Outlook.ContactItem 'folder item
Dim dbs As Database, rst As Recordset
Dim strTitle As String, strFirstName As String, strLastName As String,
strSuffix As String, strCompany As String
Dim strLastNameFirst As String, strEMailAddress As String, strNickName
As String
Dim lngResult As Long, lngcount As Long, lngPosition As Long
On Error Resume Next
Set olOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set olOutlookApp = CreateObject("Outlook.Application")
End If
Set olNms = olOutlookApp.GetNamespace("MAPI")
Set olFldrP = olNms.Folders("Public Folders")
Set olFldrP = olFldrP.Folders("All Public Folders")
Set olFldr = olFldrP.Folders("Client Email Contacts")
Set olItms = olFldr.Items
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryListEmailableClients", dbOpenSnapshot)
lngcount = rst.RecordCount
For lngPosition = 1 To lngcount
With rst
strTitle = Nz(![prefix])
strFirstName = Nz(![First Name])
strLastName = Nz(![Surname])
strSuffix = Nz(![suffix])
strCompany = Nz(![Company])
strLastNameFirst = Nz(![Surname]) & ", " & Nz(![First Name])
strEMailAddress = Nz(![Email Address])
strNickName = Nz(![dear])
End With
Set olItm = olItms.Add("IPM.Contact")
With olItm
.Title = strTitle
.FirstName = strFirstName
.LastName = strLastName
.CompanyName = strCompany
.suffix = strSuffix
.NickName = strNickName
.Email1Address = strEMailAddress
.Save
.Close (olSave)
End With
rst.MoveNext
Next lngPosition
End Function