Results 1 to 9 of 9
  1. #1
    SirArch is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Netherlands
    Posts
    5

    How can I create a flexible query where the parameter is created by environ("username")

    To control access to specific data in a multi-user database on a network without having to request the users to do anything, I want to take the Environ("username") return and pass it as a parameter to a flexible query.



    Many searches and reading of my three thick reference works have failed to turn up any way of doing that?

    Any thoughts?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    in a form put valuers, then run the query using the form as params:

    txtUser = Environ("username")
    docmd.openquery "qsMyQuery"

    where qsmyQuery =
    select * from table where [userID] = forms!frmMain!txtUser



  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You may want to investigate Role Based Access Control to see how the pieces fit together.
    It isn't clear what exactly you want to "control/restrict access to", nor how many users there are.

    Typically you identify users and associate a user with a Role; then you have additional info that allows/prohibits a Role to accessing/seeing/using specifically identified objects.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Access does not recognize Environ() function but VBA does. So build a custom function in a general module that calls Environ("USERNAME") then call the custom function from query or form.
    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
    SirArch is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Netherlands
    Posts
    5

    This looks like a good start

    I'm not quite sure what you mean by 'valuers', though.

    Thanks for the help so far.



    Quote Originally Posted by ranman256 View Post
    in a form put valuers, then run the query using the form as params:

    txtUser = Environ("username")
    docmd.openquery "qsMyQuery"

    where qsmyQuery =
    select * from table where [userID] = forms!frmMain!txtUser



  6. #6
    SirArch is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2015
    Location
    Netherlands
    Posts
    5
    Thanks for the tip. Not quite what I need, though. I want to grant access automatically by using username as the role definer to run the flexible query.


    Quote Originally Posted by orange View Post
    You may want to investigate Role Based Access Control to see how the pieces fit together.
    It isn't clear what exactly you want to "control/restrict access to", nor how many users there are.

    Typically you identify users and associate a user with a Role; then you have additional info that allows/prohibits a Role to accessing/seeing/using specifically identified objects.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Here is a data model showing the entities and relationships involved in role based access control.

    The model and response are located here.




  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Did you see post 4?

    How will you manage each user's permissions? Most likely will involve a Users table with info on user permissions.

    Do records have UserID that can be used as filter criteria?

    Do you want to manage availability of forms/buttons?
    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.

  9. #9
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    to use it in a query , build this FUNCTION for use in queries...

    Code:
    Public Function getUserID() As String
    getUserID = Environ("Username")
    End Function
    in sql ...
    select getUserID() as USER from table

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

Similar Threads

  1. Replies: 1
    Last Post: 07-21-2015, 03:38 PM
  2. Replies: 8
    Last Post: 07-15-2014, 05:56 PM
  3. Windows Log In "Username" in an append query
    By jlgray0127 in forum Queries
    Replies: 1
    Last Post: 02-26-2013, 09:46 AM
  4. Replies: 1
    Last Post: 02-17-2013, 04:46 PM
  5. Environ("username") ---> #Name? Error
    By KiEESH in forum Forms
    Replies: 2
    Last Post: 02-15-2013, 07:23 AM

Tags for this Thread

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