I have a VB6.0 application that creates a Crystal report and sends it out via Outlook 2000 e-mail. It also creates a file listing those e-mail recipients. I want this list e-mailed to the user that is currently running the application. Therefore I need to extract the current user's Outlook e-mail address.
I have used the following code to do this:
Public Function CurrentUserEmailaddress() As String
Dim straddresses
Dim CdoSession As MAPI.Session
Set CdoSession = New MAPI.Session
'Set objSession = CreateObject("MAPI.Session")
On Error Resume Next
CdoSession.Logon 'ShowDialog:=True, NewSession:=False
Select Case Err.Number
Case -2147221231
On Error GoTo 0
On Error Resume Next
CdoSession.Logon ShowDialog:=False, NewSession:=True ', profileinfo:="MSXServer" & vbLf & Environ("UserName")
If Err.Number <> 0 Then
CurrentUserEmailaddress = "admin@XXXXX.XXX"
Exit Function
End If
End Select
straddresses = CdoSession.CurrentUser.Address
CdoSession.Logoff
Set CdoSession = Nothing
CurrentUserEmailaddress = straddresses
End Function
This code was taken and modified form a previous post in this forum. I works. The message is e-mailed to the correct user. BUT the application dies with a fatal error after it sends the mail. The code that sends the mail is:
strEMailSenderName1 = CurrentUserEmailaddress
Set objOL = CreateObject("Outlook.Application")
Set objEMail = objOL.CreateItem(olMailItem)
With objEMail
.Recipients.Add strEMailSenderName1
.Subject = "Maximum Leave Notification Lists"
.Body = strFromFileTEXT
.Send
End With
'
Set objEMail = Nothing
Set objOL = Nothing
If I hard code an e-mail address in the the above routine the process terminates normally, With the function call to extract the address is gets the fatal error.
This all happens in a Windows NT 4.0 environment.
Thanks for any insight.



