Results 1 to 7 of 7
  1. #1
    grahamkida is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    3

    Variable user admin can set for use in multiple VBA Class Objects in App

    In VBA I have created a simple method to hide/ show content based on user type using an unbound field (usually hidden in the underlying form) - "Me![Version]"



    Code:
    'SetversionMe![Version] = "Usertype3"
    
    
    If Me![Version] = "Usertype1" Then
    Me![NavigationButtonManagementReports].Visible = False
    End If
    
    
    If Me![Version] = "Usertype2" Then
    Me![NavigationButtonManagementReports].Visible = False
    End If
    
    
    If Me![Version] = "Usertype3" Then
    Me![NavigationButtonManagementReports].Visible = True
    The issue I'm having is that this this is used across multiple forms to control visible content and for each I have to manually code in the the User type in VB editor before creating a release version for that user type.

    Is there a way to set the UserType once (using a form or table) for Me![Version] which can then be referenced for user type across all form class VB objects?

    Thanks Graham

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    usual way is to have a user table and perhaps a group table (admin/management/data processor/whatever), perhaps with related tables which set the permissions for that group for what they can see and do.

    not clear how your usertype/version values are being populated, my assumption below is it is being populated in the recordsource when the form is loaded

    if it is always just the NavigationButtonManagementReports button you want to hide/show and it is called the same in every form you can create a public function in a module

    Code:
    function showHideReports(frm as form)
        frm.NavigationButtonManagementReports.Visible=frm.Version = "Usertype3"
    end function
    and in each form load event property put

    =showHideReports([FORM])

    where you would normally see [Event Procedure]

  3. #3
    grahamkida is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    3
    Thanks for this suggestion - currently I prepare 4 user group variations of the Access App to deploy into specific folders which only certain users (aligned to their type) can access. Users do not log into the app. Without redesigning the user access I just want to set the current version once in each app before deployment and not in every form where the code show's/hide's elements based on usertype.

    Basically replacing Set Me![Version] = "UserType3" to Set Me!![Version] = GlobalVariable (Set to "UserType3" once somewhere else) or = RecordSource [UserStatusTable]UserSetField (Again set to "UserType3" in single record/ field of table).

    I think this must be possible - I just can't find the method/ syntax on how this can be done..

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    seems a weird way of managing it, version control will be unnecessarily complex. Also from your description, you could have multiple users of each type opening the same front end (I presume the database is split) which is a really big no-no - that way lies corruption.

    But lets say you stick with your method, then your code could reference the project path to identify the folder it is in

    function showHideReports(frm as form)
    frm.NavigationButtonManagementReports.Visible=instr(currentproject.path,"managers")>0
    end function

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    In the Autoexec you could set a Tempvar to your User Type and refer to that perhaps?

    Your test as you have posted only needs to be
    Code:
    If TempVars("UserType").Value = "Usertype3" Then
        Me![NavigationButtonManagementReports].Visible = True
    Else
        Me![NavigationButtonManagementReports].Visible = False
    End If
    Otherwise I would use a Select Case statement
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    grahamkida is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2023
    Posts
    3
    Thanks everyone for your advices - will give them a go and let you know how I get on

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You can use a TempVar as already suggested, a (hidden) control on a hidden startup form, a global variable, a dLookup in a users table (get the logged user using Environ("UserName") and look up the corresponding version in the table)....
    Have a look at my free utility that does custom access control here:
    https://forestbyte.com/ms-access-uti...access-levels/

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 7
    Last Post: 06-19-2019, 04:11 PM
  2. Navigate to Class Objects in VBA via command button
    By zashaikh in forum Programming
    Replies: 2
    Last Post: 04-24-2019, 01:23 PM
  3. Replies: 19
    Last Post: 06-08-2016, 07:55 AM
  4. Implementing Custom Class Objects-Where should they go?
    By Monterey_Manzer in forum Database Design
    Replies: 5
    Last Post: 04-07-2014, 12:15 PM
  5. Restricted Access - Admin v. User
    By need_help12 in forum Security
    Replies: 4
    Last Post: 04-30-2012, 09:51 AM

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