Results 1 to 12 of 12
  1. #1
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61

    Not able to display User's Name on Form called Worker's Console

    I need some help on displaying the User's Name on the Worker's Console Form.

    I have tried to use a Global Variable but I think due to my limited understanding, which is the cause of it


    not to work properly.

    I wanted the Text box named "Text32" to display the name as long as the page is loaded.
    ***I would rather it display as a label if at all possible. (Can I see both methods?)

    Please help???

    Please see attachment.

    Thank you.
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    'for USERID
    Environ("Username")

    'OR FULL NAME
    CurrentUser()

  3. #3
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61
    I want to apply the pvUserB variable on the Form "Worker Console"

    I am not sure how to do this.

    I have tried Text32 = pvUserB and made Global pvUserB As String.

    But this seem to not work.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    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.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    If you defined pvUserB as global then it can be assigned anywhere , anytime.
    did you assign it?
    (But there's no need since users can be seen anywhere, anytime via system variabls)

    FYI, A global variable should be defined as Global gvUserB As String.
    the p indicates a paramater, g global.
    if it is a param, then you lost your global setting.

  6. #6
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61
    I set the following:

    Option Compare Database
    Global pvUserB As String
    Option Explicit

    The value is placed in the Call Form:

    [QUOTE][pvUserB = DLookup("[User_Name]", "User_List", "[Code_number] = " & CLng(Me.Text3))/QUOTE]



    When the form loads. This should apply the Global variable to Text32 for display.
    [QUOTE][Private Sub Form_Load()
    Text32.Value = pvUserB
    DoCmd.GoToRecord , "", acNewRec
    End Sub
    /QUOTE]


    I have tried if both ways....gvUserB and pvUserB.
    I am not sure what is going on.


  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yes, it can be done.
    If you are going to use global variable, you would need a line in the code for "Sub Command14_Click()" (poor choices for object names, BTW)
    Code:
    pvUserB = Me.Text3
    Then, after the form "Worker_Console" is open, you could use the form load event to set text32 to pvUserB:
    Code:
    Me.Text32 = pvUserB 
    'To set a label to a name, you have to set the "Caption" property.
    Me.LabelName.Caption = pvUserB



    I didn't use the global variable method. After the form is open, I set the value of the controls.
    See the code...

  8. #8
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61
    Thanks for the help. Yes this really works....Also thanks for explaining both way. This really help if I have to use further down the building process.


  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have to understand the SCOPE of variables.

    OK, last db change....

    I changed the GLOBAL variable name to "gvUserB" and removed some local variable declarations from procedure "Sub Command14_Click()". There are a couple of message boxes to display the value of the global variable for demonstration purposes.

  10. #10
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61
    Thanks for your information and help. That was pretty cool with the message box. I did not realize the actions that happens behind the scene. Global variables is a powerful tool.

    Thanks Steve.

  11. #11
    Alphix is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    61
    Can you break down the explanation the following?

    I do not know what is actually happening here.

    Also what is cbo?

    Private Sub cboCodeNumber_AfterUpdate()
    Me.Text3 = Me.cboCodeNumber
    Call Command14_Click

    End Sub
    Thanks

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Private Sub cboCodeNumber_AfterUpdate()   "<< This is the after update event of the combo box
    
         Me.Text3 = Me.cboCodeNumber  "<< this sets the value of the text box control "Text3" to the value of the combo box selection
    
         Call Command14_Click  '  << this executes the commands just like you had clicked the enter button.
    
    End Sub
    So after setting the value of Text3, the code execution jumps to the procedure "Command14_Click". after all of the commands in "Command14_Click" have been executed, the execution jumps back to the line after the Call, which is "End Sub". Just like entering in 111 and clicking "Enter".





    ---------------------------------------
    (Instead of leaving the button control the default name, I would have named the button "btnEnter". Then the after update event would look like:
    Code:
    Private Sub cboCodeNumber_AfterUpdate()
        Me.Text3 = Me.cboCodeNumber
        Call btnEnter_Click
    
    End Sub
    Which tells you more: "Command14_Click" or "btnEnter_Click"??
    I always tale the time to rename control to something meaningful.

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

Similar Threads

  1. Replies: 13
    Last Post: 10-02-2014, 09:29 AM
  2. Display query results on user form
    By Ganesh7299 in forum Access
    Replies: 3
    Last Post: 12-28-2013, 06:19 AM
  3. Replies: 13
    Last Post: 11-18-2013, 02:20 PM
  4. Replies: 6
    Last Post: 02-21-2013, 10:52 AM
  5. Replies: 2
    Last Post: 11-08-2012, 11:04 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