Consulting

Results 1 to 10 of 10

Thread: Solved: Current Users Email Address

  1. #1

    Solved: Current Users Email Address

    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

  2. #2
    Anyone??? HELP!

  3. #3
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    Maybe you could try this one:
    [VBA]Application.Session.CurrentUser.Address[/VBA]

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

    Daniel

  4. #4
    Thanks, I'll give it a try

  5. #5
    ahhhh it was a good try. Application.Session.CurrentUser.Address returns the Users Name, not the email.

    Thanks anyway...

  6. #6
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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)[VBA]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 Sub[/VBA]3. You open Outlook in the background and try[VBA]Application.Session.CurrentUser.Address[/VBA](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
    K :-)

  7. #7
    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 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?

  8. #8

    got it!

    Ok this is what worked for me....

    [VBA]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 [/VBA]

    Thanks for the help!

  9. #9
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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
    K :-)

  10. #10
    Your correct. With the system I am working on, it works great, but may not work on others. Thanks for the help.

    Bone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •