locked
Attempting to build a query for auto-generated text RRS feed

  • Question

  • I'm currently attempting to build a form that auto-generates the username field for me.

    So far, I'm using the =Environ("Username") input, however, due to how our profiles are loaded on our computers, it's populated with our cert ID's, not the actual username. What I would like to do is based off of the user ID, which would be a string like "181515F", have it pull up the username in that same table.

    I'm sure this is a really simple fix, I however cannot for the life of me figure out how to do it. I would've just Google'd it, but I couldn't even really figure out how to ask the question.

    Thanks!


    Derek Jones IT Project Manager

    Sunday, April 10, 2016 5:20 PM

Answers

  • >>>What I would like to do is based off of the user ID, which would be a string like "181515F", have it pull up the username in that same table.

    According to your description, please correct me if I have any misunderstandings on your question, I suggest that you could use the DLookup function to get the value of a particular field from a specified set of records (a domain). Use the DLookup function in a Visual Basic for Applications (VBA) module, a macro, a query expression, or a calculated control on a form or report.

    For more information, click here to refer about DLookup Function

    >>>I would've just Google'd it, but I couldn't even really figure out how to ask the question.

    I suggest that you could provide sample code, screenshot, or unload your Access database file on OneDrive, that will help us reproduce and resolve your issue.

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Thursday, April 21, 2016 7:55 AM
    Wednesday, April 13, 2016 5:26 AM

All replies

  • You can ask Windows who is logged in: http://access.mvps.org/access/api/api0008.htm


    -Tom. Microsoft Access MVP

    Sunday, April 10, 2016 10:28 PM
  • You execute SELECT username FROM <yourTable> WHERE ID='181515F'

    In VBA:

    Dim theTable as String
    Dim theID as String
    Dim theSQL as String
    Dim db As DAO.Database
    Dim rs as DAO.Recordset
    Dim theUser as String

    theTable = "myTable"
    theID = "181515F"
    theSQL = "SELECT username FROM " & theTable & " WHERE ID = '" & theID &"';"

    Set db = CurrentDb
    Set rs = db.OpenRecordset(theSQL)

    theUser = rs!username

    ... etc ...


    Best regards, George




    Tuesday, April 12, 2016 3:37 PM
  • >>>What I would like to do is based off of the user ID, which would be a string like "181515F", have it pull up the username in that same table.

    According to your description, please correct me if I have any misunderstandings on your question, I suggest that you could use the DLookup function to get the value of a particular field from a specified set of records (a domain). Use the DLookup function in a Visual Basic for Applications (VBA) module, a macro, a query expression, or a calculated control on a form or report.

    For more information, click here to refer about DLookup Function

    >>>I would've just Google'd it, but I couldn't even really figure out how to ask the question.

    I suggest that you could provide sample code, screenshot, or unload your Access database file on OneDrive, that will help us reproduce and resolve your issue.

    Thanks for your understanding.
    • Marked as answer by David_JunFeng Thursday, April 21, 2016 7:55 AM
    Wednesday, April 13, 2016 5:26 AM