Results 1 to 13 of 13
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force format of network name (2000)

    Hi,
    Is there a way to enforce the format of a name obtained from the network login in Access. I produce a letter from a record in a database and dependant upon how people log in in the morning is dependant upon how the name appears.
    For instance.
    joe.Bloggs
    JOe.BLOggs

    Ideally I'd like to do it in the following format Joe Bloggs, without the " . " in the middle.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force format of network name (2000)

    Will the login name ALWAYS be of the form FirstName.LastName? Or are variations possible

  3. #3
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Yes, its always in the format of FirstName.Lastname. This cannot be changed.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Force format of network name (2000)

    How do they manage to log in to a network with differing case? Every network I've ever worked on was case sensitive. Or are you talking about Access security, which is NOT case sensitive?
    Charlotte

  5. #5
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Nope, the networked name can be any case as long as it is in the format of firstname.lastname (with the dot). This is when the user logs into the system when it is booted up.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force format of network name (2000)

    Say that you have the network login name in a string variable named strLogin. Use the following code to get the name in the form you want:

    strFormattedName = StrConv(Left(strLogin, InStr(strLogin, ".") - 1), vbProperCase) & " " & StrConv(Mid(strLogin, InStr(strLogin, ".") + 1), vbProperCase)

  7. #7
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    So presumably in the following code:

    Option Compare Database
    Option Explicit
    Dim fOKToClose As Boolean

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
    (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

    Public Function NetUser() As String
    Dim strName As String, strUserName As String
    strName = vbNullString
    strUserName = Space(255)
    If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
    NetUser = left(strUserName, InStr(strUserName, vbNullChar) - 1)
    ***************************add code here*****************************************
    Else
    NetUser = "-unknown-"
    End If
    End Function


    Would I add the code at the ***************************add code here***************************************** part?

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Yes, and replace strLogin from <!profile=HansV>HansV<!/profile>'s function with NetUser
    Francois

  9. #9
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Sorry, being thick here..........something like this?

    Option Compare Database
    Option Explicit
    Dim fOKToClose As Boolean

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
    (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

    Public Function NetUser() As String
    Dim strName As String, strUserName As String
    strName = vbNullString
    strUserName = Space(255)
    If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
    NetUser = left(strUserName, InStr(strUserName, vbNullChar) - 1)
    strFormattedName = StrConv(left(NetUser, InStr(NetUser, ".") - 1), vbProperCase) & " " & StrConv(Mid(NetUser, InStr(NetUser, ".") + 1), vbProperCase) Else
    NetUser = "-unknown-"
    End If
    End Function

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force format of network name (2000)

    The "Else" should be on the next line, not on the same line with another instruction.

  11. #11
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Yep, thats been done. It displays the error:
    Compile Error:
    Variable not defined
    When you enter the code it highlights strFormattedName =

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Force format of network name (2000)

    Try to think about what your code is doing. strFormattedName was only an example in my reply. Your function needs to set a value for NetUser.

    ...
    NetUser = StrConv(left(NetUser, InStr(NetUser, ".") - 1), vbProperCase) & " " & StrConv(Mid(NetUser, InStr(NetUser, ".") + 1), vbProperCase)
    Else
    ...

  13. #13
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force format of network name (2000)

    Thank you Hans.
    I did consider that the strFormattedName was incorrect as this was being set via the coding that followed it, whereas the NetUser format needed to be changed instead. Unfortunately I'm not very good with coding so was unsure of my decision............. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

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