locked
Pass login username to another userform Excel vba RRS feed

  • Question

  • Hi,

    I have a login form with username and password. I wanted to pass the username entered to displayed in another userform. This is what i did with my codes. Upon running the application and use the user login and open the MainFrm.

    the Username does not displayed. it is an empty. May I ask your help guys. thanks.

    --put the code on the first line of Loginfrm
    Option Explicit
    Dim iCounta As Integer
    Public UserName As String
    --after the user successfully login i put this codes
    Unload Me  --unload the loginfrm
    UserName = TextUser.Value   
    MainFrm.Show
    --In MainFrm at userform_initlialize i put this code
    --to display the Users login name
    Me.Label1.Caption = UserName

    Wednesday, March 5, 2014 12:43 AM

Answers

  • Re:  UserForm with Textbox

    Switch two lines so that "Unload Me" comes after "UserName = TextUser.Value"

    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    Wednesday, March 5, 2014 1:16 AM
  • Solved. Just place the Public Username As string at modules not inside the userform. thanks.
    Wednesday, March 5, 2014 8:26 AM

All replies

  • Re:  UserForm with Textbox

    Switch two lines so that "Unload Me" comes after "UserName = TextUser.Value"

    '---
    Jim Cone
    Portland, Oregon USA
    https://goo.gl/IUQUN2 (Dropbox)
    (free & commercial excel add-ins & workbooks)

    Wednesday, March 5, 2014 1:16 AM
  • Hi James,

    Thanks for the reply. Switching those 2 lines you mention still the username is empty when MainFrm show. try to debug when cursor point to the first line textuser value name "admin" transfer to username. after unload username is already empty. try another work around i put another  "UserName = Me.TextUser.Value" after the unload me when MainFrm show still username is empty. Thanks.

                UserName = Me.TextUser.Value
                Unload Me
                MainFrm.Show
    Wednesday, March 5, 2014 8:05 AM
  • Solved. Just place the Public Username As string at modules not inside the userform. thanks.
    Wednesday, March 5, 2014 8:26 AM