Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Posts
    8

    Unanswered: pass username to various forms

    Hello! I'm new to Access 2007. I just created a login form. The login form works fine. How do I pass the user that logged in to the database to various forms? If a user opens Data Entry form, I want that username to appear on the Data Entry form and so on.

    thanks,
    Dave

  2. #2
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Using Access 2003 I created a form called frm_utility with a text box called user_id that will store the user id of the user logging in.

    After I validate the user login process etc I use the following code to open and hide the frm_utility and then store the user id on this form. the form frm_main is the name of the Login form.

    ' open and hide the utility form frm_utility
    ' this form will be used to store the user id for as as required e.g recording the user id of an
    ' user adding records etc.
    DoCmd.OpenForm "frm_utility", , , , , acHidden

    'store the user id on the utility form frm_utility
    Forms!frm_utility!user_id = Forms!frm_main!user_id

    I then reference the user id field on the form frm_utility when I require the user id for data entry forms etc.

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Just use a global variable. Then your login screen can set it and all other forms can read it.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Mar 2009
    Posts
    8
    Thanks poppa Smurf. I'm not sure how to pass value as you stated
    Forms!frm_utility!user_id = Forms!frm_main!user_id

    So, I'm using StarTrekker's suggestion. The global variable works well.
    I'm defining a global currentUserID as integer.

    When I make the call below, the listbox is empty. What am I doing wrong? no error tho.

    lstStoreName.RowSource = "SELECT tblLogin.[ID], tblLogin.[uname] FROM tblLogin WHERE (((tblLogin.[ID])='currentUserID'))"

    thanks again,
    Dave

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Queries can't see variables.

    Use this:

    lstStoreName.RowSource = "SELECT ID, uname FROM tblLogin WHERE ID='" & currentUserID & "'"

    or the following if ID is numeric:

    lstStoreName.RowSource = "SELECT ID, uname FROM tblLogin WHERE ID=" & currentUserID
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Mar 2009
    Posts
    8
    Hello again.

    thanks! The sql works great. Now I have another problem.

    I'm creating a combo box with a list of names. When user selects a name from the combo box listing, i want the name to display on a text box. It was working fine but now the text box is just blank.
    cboName <- this contains a list of names
    txtName <- this displays the selected name.

    thanks again for any help,
    Dave

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    new problem new question please, dems der rules

    ..it helps you get answers form more people (many will see a question thats got a good few answers and not look at it, assuming there was someone helping you already)

    ..it helps people searching for an answer when they have a problem. it doens't confuse people if there are different suggestions and answers

    ..it helps you as you get more focussed attention

    ...
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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