VBA code to return the current Userid Email address

G

Guest

I have code that will send an email upon completion of the task, it looks at
the userid and returns the email address. Atleast on the local machine.
Note: current userid is the alias field in Outlook.

When I tried the code on another it could not find the email address for
that userid.

Is there such code that will do somekindof cross reference or DLOOKUP on the
Outlook global address book?

Public Function ReturnNetworkName() As String
'RETURNS NETWORK LOGIN ID OF CURRENT USER
ReturnNetworkName = Environ("UserName")
End Function
Function SendMessage() 'DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
'Dim objOutlookAttach As Outlook.Attachment
Dim strLtrContent, strLtrContentEnd, strHyperLink
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(ReturnNetworkName)
objOutlookRecip.Type = olTo

strLtrContent = "The most recent PLANIT is avail for you to copy to your
local drive and scrub in your Core Scenario Planning and Dimensioning." & _
vbCrLf & vbCrLf & "Please Click on the following link, this will direct you
to a SAVE AS dialog box, which defaults to your [MY Document] file, you can
Click OK or redirect to the desired directory." & _
vbCrLf & vbCrLf & " "
strLtrContentEnd = "For 'Missing Node', 'Missing Market' or 'Missing Region'
issues, please email Karen Schaefer. For trending related issues, please
email or call Tanvir Rahman."

strHyperLink = "RegionFileCopy.mdb"

..Subject = "Manual PlanIT Forecast for Scrubbing is Completed and Ready for
Your Use for the NCP"
..BodyFormat = olFormatHTML
..HTMLBody = "<HTML><HEAD><META http-equiv=Content-Type content=" & Chr$(34)
& "text/html; charset=iso-8859.1" & Chr$(34) & "></HEAD>" & vbCrLf & _
"<BODY>" & strLtrContent & "<A HREF=" & Chr$(34) & strHyperLink & Chr$(34) &
">" & strHyperLink & "</A><br><p>" & strLtrContentEnd & "</BODY></HTML>"
..Send
End With

' Resolve each Recipient's name.
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Function


Thanks,

Karen
 
N

Nikos Yannacopoulos

Karen,

I suspect the problem is on the Outlook side rather that on the Access
side: maybe the user on whose machine it failed doesn't have the global
address book in outlook, or isn't registered in it. One first step to
verify is to open Outlook on the user's machine (having logged in a the
user themselves), start creating a new message, type the user's Windows
logon ID in the To: box and press Ctl+K. If my guess is correct, outlook
will come back with a *(no suggestion)* response.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top