Results 1 to 4 of 4
  1. #1
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    Username as Global Variable


    Hello! I have a form where the user enters some information, such as their user name. This is then saved into a table titled "Users". I have been asked to make the user name entered a global variable. I have no idea how to go about doing this. help please

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by imintrouble View Post
    Hello! I have a form where the user enters some information, such as their user name. This is then saved into a table titled "Users". I have been asked to make the user name entered a global variable. I have no idea how to go about doing this. help please
    Describe what you are trying to achieve with this

  3. #3
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    The idea is to have this used in a log-in type form. When someone is working on our database the form will pop-up having them enter their information such as User name, user type, and their e-mail address. When the information is saved to the database, it would be nice to have the user name as a global variable so that it may be used all over the database for the time that they are "logged on".

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    you can go 2 ways about this:
    * create a class module UserInfo (or something like that) and write all properties end methods you need concerning users and security in this class. In the rest off your code you can use this class as a normal object.

    * use the windows user name; one way of getting this is the following function (mind you for windows 64 you'll probably need to add theptrsafe instruction)

    Code:
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function getOSUserName() As String
    On Error GoTo Err_getOSUserName
    
        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
            getOSUserName = Left$(strUserName, lngLen - 1)
        Else
            getOSUserName = vbNullString
        End If
        
    Exit_Err_getOSUserName:
        Exit Function
    
    Err_getOSUserName:
        Call gsgErrorHandling
        Resume Exit_Err_getOSUserName
        
    End Function
    greeting
    NG

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Replies: 4
    Last Post: 07-14-2011, 12:55 PM
  3. How to declare Global Variable
    By ganeshvenkatram in forum Access
    Replies: 1
    Last Post: 06-16-2011, 05:18 AM
  4. Dlookup in query using Global variable
    By newwales in forum Access
    Replies: 1
    Last Post: 06-03-2011, 03:47 PM
  5. Declare a Global Variable and Use it on Forms
    By jackkent in forum Access
    Replies: 9
    Last Post: 10-07-2010, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums