PDA

View Full Version : Solved: Current Users Email Address



boneKrusher
02-02-2006, 06:31 AM
Hi All,

Is it possible to get the current Users email address (outlook) using VBA?

I have some forms that are auto generated from ACCESS and would like to have the current users email address automaticly exported to a word template.

Thanks,

Bones

boneKrusher
02-06-2006, 03:24 PM
Anyone??? HELP! :(

Steiner
02-07-2006, 02:23 AM
Maybe you could try this one:
Application.Session.CurrentUser.Address

where Application is you Outlook application, so if you're running this from Access, replace Application with the Outlook object you use.

Daniel

boneKrusher
02-07-2006, 08:38 AM
Thanks, I'll give it a try

boneKrusher
02-07-2006, 08:52 AM
ahhhh it was a good try. Application.Session.CurrentUser.Address returns the Users Name, not the email.

Thanks anyway...

Killian
02-07-2006, 09:37 AM
This isn't quite as straight-forward as you might hope...

Three typical scenarios are:

1. The database has a list of users who are required to register and provide their details which are stored in a table (like this forum)

2. Your are on a domain where the email addresses are derived from the NT user name (windows login)Private Declare Function GetUserName& Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long)

Public Function WindowsUserName() As String
' ---------------------------------------------
' Function to extract the name:
' ---------------------------------------------
Dim szBuffer As String * 100
Dim lBufferLen As Long

lBufferLen = 100

If CBool(GetUserName(szBuffer, lBufferLen)) Then

WindowsUserName = Left$(szBuffer, lBufferLen - 1)

Else

WindowsUserName = CStr(Empty)

End If

End Function

Sub test()
'usage...
MsgBox WindowsUserName & "@mydomain.com"

End Sub3. You open Outlook in the background and tryApplication.Session.CurrentUser.Address(where Application refers to Outlook)
This is by no means reliable and probably won't produce what your looking for if the user isn't on an Exchange server

boneKrusher
02-07-2006, 10:28 AM
Ok, we're getting close, here's whats happening:

scenario:
1. Last case scenario - If I can't figure it out, Ill do that.
2. Works, but returns login jdoe@mydomain.com (name@mydomain.com) rather then : john.doe@mydomain.com
3. Returns full name: doe, john
4. I can run "Application.Session.CurrentUser.Address "

split the table and add the domain.

What do you think?

boneKrusher
02-07-2006, 11:15 AM
Ok this is what worked for me....

Dim newe As String
Dim full As String
Dim last As String
Dim first As String
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
newe = olApp.Session.CurrentUser.NAME

last = Left(newe, InStr(1, newe, ",") - 1)
first = Mid(newe, InStr(1, newe, ",") + 1)
Me.Text1 = first & "." & last & "@domain.com"

DoCmd.SetWarnings True

Thanks for the help!

Killian
02-07-2006, 12:59 PM
A lot of this depends how the mail server and the local network are configured.
If it works then thats a solution... but it might not be a very portable one.

I've taken the liberty of marking the thread as solved

boneKrusher
02-08-2006, 04:39 AM
Your correct. With the system I am working on, it works great, but may not work on others. Thanks for the help.

Bone.