Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Location
    Belfast, UK
    Posts
    87

    Unanswered: Probably a stupid question.

    Hi,

    I've been building a database with user logon screens and want to user the user name and groupid as public variables on all the forms that require this information.

    so far I have a module called MdlPublicVariables

    with the following code.

    Option Compare Database

    Public GroupID As Long
    Public UserID As Long

    How do I store this data once the user logs on, and call it when required.
    Also I'd like to be able to do something similar for command etc. that appear on multiple forms i.e cancel etc.

    Thanks!

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    With the next function you can get the User log in name


    Private Declare Function apiGetUserName Lib "ADVAPI32.DLL" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    ' APIs Functions

    Function LoggedUserName() As String
    ' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
    LoggedUserName = Left$(strUserName, lngLen - 1)
    Else
    LoggedUserName = vbNullString
    End If
    End Function

  3. #3
    Join Date
    Dec 2003
    Location
    Belfast, UK
    Posts
    87
    That'll work fine but unfortunately I'm not using windows logon. just a table within the database that has all the user details.

    Thanks though.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    ...then you just need a global variable to hold the logon stuff.

    make a module and type:
    global gstrUserLogonName as string

    ...then you can refer to gstrUserLogonName anyhere in your application.
    gstrUserLogonName = strWhateverYouLike
    strWhatIsLogin = gstrUserLogonName

    if you need to pull this info for a query, then you also need a function in the module to return the value:
    public function strWhoIsLoggedOn() as string
    strWhoIsLoggedOn = gstrUserLogonName
    end function


    (but keep your modules small - if you refer to ANY var/const/func/sub in a module, the whole module is loaded in memory and stays there until you quit the application)

    izy
    currently using SS 2008R2

Posting Permissions

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