Results 1 to 4 of 4
  1. #1
    FOURKAYSDAD is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2022
    Posts
    1

    How do i populate a login name in ms access on every form the user opens to use

    ----- ' MYUSERNAME is a global variable

    MYUSERNAME = DLookup("EMPNAME", "USERACCOUNT", "USERNAME = '" & Me.USERNAME.Value & "'") MsgBox (MYUSERNAME)

    The above code captures and displays the login name. no problem.

    The issue is when the variable (MYUSERNAME) is used in a form it comes out blank. I learnt from a place that i could use TEMPVARS as solution.
    My question is : how could tempvars solve this issue for me please? Please give CODE using TEMPVARS and MYUSERNAME


    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    A textbox expression can reference TempVar variable.

    Why don't you research use of TempVars and make an attempt? I never used myself but I understand them just from reading about.

    A public function can be called by a textbox expression and that function can provide the MYUSERNAME global value.

    =MyUser()

    Public Function MyUser()
    MyUser = MYUSERNAME
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    TBH I would have thought a global variable would work just as well as a TempVar?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Access queries and controls cannot see global variables or constants.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-27-2013, 07:56 AM
  2. HELP>Access 2010 User Login Form Code.
    By zaaimanm in forum Programming
    Replies: 5
    Last Post: 10-22-2012, 07:28 PM
  3. User Login Form
    By glen in forum Forms
    Replies: 21
    Last Post: 09-17-2012, 09:09 AM
  4. Replies: 6
    Last Post: 08-07-2012, 02:44 PM
  5. Replies: 1
    Last Post: 03-07-2011, 10:48 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