Share via

MS Access SQL Query based on Windows environ username.

Anonymous
2016-08-08T21:24:29+00:00

Hello,

I'm trying to implement the solution found here to query records based on the username matching the windows login of the user running the query. When I try to execute the query I receive the error "Undefined function 'GetUserName' in expression. Any suggestions on how to proceed? It's a simple select query based on a single table.

Thanks,

Jason P

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2016-08-09T14:03:53+00:00

    Was trying different tutorials. They aren't all in use however and will be deleted once I get one to work.

    In response to HansV I recreated the module with the name you supplied and still get the same error

    SELECT ScoreTble.EU_Num, ScoreTble.DateMod, ScoreTble.Device_Check, ScoreTble.Device_Check_Details, ScoreTble.Battery_Replacement_Program, ScoreTble.AED_Functional, ScoreTble.Batteries_Charged, ScoreTble.Electrodes_Status, ScoreTble.User, basGetUsername() AS Expr1

    FROM ScoreTble;

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2016-08-09T13:55:21+00:00

    Hans is right. As a general guideline you should adopt a naming convention that prevents the use of duplicate object names and Reserved Words. In this list of module names we see four different styles, which is three too many.

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2016-08-09T13:36:41+00:00

    The problem is that you have given the module the same name as the function. This confuses Access. If you rename the module to (for example) basGetUsername, the function should work.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-08-09T13:05:19+00:00

    Yes I have done that and copied the code exactly. Executing the code via the project window returns no errors however I can't add it to the query like this and other examples show.

    Was this answer helpful?

    0 comments No comments
  5. HansV 462.6K Reputation points
    2016-08-08T21:48:25+00:00

    Have you copied the code from your link into a standard module? A standard module is created by selecting Insert > Module in the Visual Basic Editor.

    Was this answer helpful?

    0 comments No comments