Results 1 to 9 of 9
  1. #1
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32

    Adjusting the Default state and search parameters of a form based on user

    Hello,

    I need help Programming some new code into a existing Access Database that also has Visual Basic Code. This Access Database contains many documents that are either hyperlinked or not and even have a form based article records (because they are from a library) if they have one.

    Now this Database will also be used for a terminal in the Library, aka a "Special Quest Account" under the network to search for Library Documents. So the Form needs to be in a certain "Default state" where some Checkmarks have the Default value of 1 and other 0. The Screenshot below "Default State" shows which checkmarks and Filters need to be ".Enabled= True" and ".Enabled= False" at default, when that specific user has logged in.

    Click image for larger version. 

Name:	Default State.png 
Views:	33 
Size:	60.1 KB 
ID:	38531

    Not only that but as an extra I would like certain "chk" and "txt" elements to be invisible on that form. The Screenshot below illustrate this:

    Click image for larger version. 

Name:	Invisiblity State.png 
Views:	33 
Size:	52.0 KB 
ID:	38532



    Now as for coding so far this is the only that seems to be relevant to do this because it does the following:



    Code:
    Private Sub Form_Load()
        Dim strCheck     As String    
        DoCmd.Maximize    
        lblUser.Caption = "Ingelogd als : " & Environ("USERDOMAIN") & "\" & Environ("USERNAME")
        strCheck = getValuefromTable("SELECT ROL FROM ADMIN_ROLLEN WHERE GEBRUIKER = '" & Environ("USERNAME") & "'")
        If Environ("USERDOMAIN") = XXX" And strCheck = "Admin" Then
            btnAdmin.Enabled = True
            btnBIB.Enabled = True
        Else
            If Environ("USERDOMAIN") = XXX" And strCheck = "BIB" Then
                btnAdmin.Enabled = False
                btnBIB.Enabled = True
            Else
                btnAdmin.Enabled = False
                btnBIB.Enabled = False
            End If
        End If   
        writeLog "LOGON", lblUser.Caption
        CurrentDb.Execute "UPDATE ADMIN_FOLDERS SET FILTER_CHECK2 = True", dbFailOnError
    The code that is Highlighted in Bold is the part where the code I think should been written. But in fact what we have here are Three Forms. The Code above is MAIN_FRM while the Actual Ellements are on the FRM Documents. So how to do this?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You're missing a " mark in your line of code

    If Environ("USERDOMAIN") = "XXX" and strCheck = "BIB" Then

    i'm assuming you've just chopped out an actual domain name and this is correct in your actual code.

    Here is how I would approach this, particularly if there are multiple controls you want to check for various users.

    Use the TAG property of each control you want to make invisible/unusable for specific users

    In TAG property put something like "BIB"

    Then you can do something like

    Code:
    Dim ctl as control
    
    if strCheck = "BIB" then
        for each ctl in me.controls
            if ctl.tag = "BIB"
                'ctl.value = null 'optional if you want to set the values to nulls
                ctl.visible = false
            Endif
        next ctl
    else
        for each ctl in me.controls
            if ctl.tag = "BIB"
                ctl.visible = true
            endif
        next ctl
    endif
    this way you don't have to trigger each control individually, and if you add controls over time they're handled with minimal effort.

  3. #3
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32

    Further Questions.

    Thank you for the response and sorry for my late reply.
    Yes the code I gave you does work as intended and I have "censored" the Domain Name for "security reasons".

    But I still have some Questions.

    For example about the ctl.tag= "BIb"? So far there does not seem to be something that creates a tag for that UserGroup, there are only two relevant user groups here in the Access Database. Mainly Admin and BIB as shown in the code. Which are pulled from this table, Gebruiker: is where the Windows PC user is has been manually registered (aka Typed). And ROL is off course the role that Windows user has been assigned.

    Attachment 38583


    So I do not see why I need to use the ctl.tag part since: I do not know how to create this and second it does not exist in the Database. The BIB part and Admin Part is just the type of user we need. So far it is only 2 groups, but I am gonna assume there is gonna be more. So thank you for suggesting something that can be expanded later. But I need some more explanation.


    To be clear, I understand that CTL means control so that mean that is the element I need to refer to right?

    I have some trouble with that because I do not seem to get the part about the ctl.tag= Bib and I do not know where to actually put it: Do I need to put it under my current code or part as the exisiting code without an End Sub? I am assuming because this is a new action it is new part of code so I would need to put it seperate but I am asking just in case.

    Better Illustration of my Question: Ignore this if you do not find this relevant:

    I also now can better illustrate what each element is in Code and what should be happening:

    Code:
    
    Subformulier ADMIN_FOLDERS
    
      Subformulier ADMIN_FOLDERS.Visible= False
    
      FILTER_CHECK.default= 0
      FRM_Documents
    
      chkbestandextensie.default= 0
      chkbestandextensie.visible= False
      txtbestandextensie.visible= False
     
    
      chkBib.Default= 1
    
      ChkBib.Visible = False
    
      chkBibGem.Default= 1
    
      chkBibGem.Visible= False

    So that is in code what needs to happen when the Usergroup BIB is currently using the database. I am sorry if I am seem to be asking the same question twice but I am kind of stuck at the moment.

  4. #4
    Minty is online now VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    The Control Tag is a property of the control, you simply set it in design mode once and forget it.

    You can with a little effort use the tag property to accomodate 3 or 4 or more user groups, see the sample database here from Colin : https://www.access-programmers.co.uk...d.php?t=293439
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Here's an example. Simple single form database look at the ON CHANGE code of the combo box at the top of the form.

    Then look at the TAG property of the controls at the bottom of the form (it is the last property in the ALL tab of your properties window)

    Notice they all say BIB. The code is just checking to see if the user is an admin (1) or a user (2). Your setup is a bit different, but one other thing is you don't need to have anyone type in a user ID you can harvest it using environ("Username"). As long as the username is defined in your database you'll be good.

    EDIT: Oops, forgot attachment
    Attached Files Attached Files

  6. #6
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32
    Thank you for the response I will keep your solution open as an Possible second route when we encounter some problems.

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    HI
    Minty referenced my example database which uses the tag property to set the state of a group of controls at once (visible/hidden, enabled/disabled or locked/unlocked).
    You can also find it at http://www.mendipdatasystems.co.uk/s...ols/4594398114
    It really is very easy to use this idea and will significantly reduce the amount of code you need.
    If you decide to use it and have any questions, get back to me
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32
    Quote Originally Posted by isladogs View Post
    HI
    Minty referenced my example database which uses the tag property to set the state of a group of controls at once (visible/hidden, enabled/disabled or locked/unlocked).
    You can also find it at http://www.mendipdatasystems.co.uk/s...ols/4594398114
    It really is very easy to use this idea and will significantly reduce the amount of code you need.
    If you decide to use it and have any questions, get back to me
    After encountering some problems with adjusting the code for a certain other form, I would like to use your possible sollution. Could we have more contact please? The Example you gave me with the Hyper Link seems easy to understand so far but translating it to my situation seems is the difficult part.

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Sure. What else do you want to know?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2018, 04:46 PM
  2. Replies: 7
    Last Post: 04-12-2014, 04:26 PM
  3. Replies: 8
    Last Post: 09-19-2013, 06:22 AM
  4. Replies: 1
    Last Post: 07-20-2012, 05:35 PM
  5. Adjusting Form size based on screen resolution
    By stombiztalker in forum Forms
    Replies: 0
    Last Post: 02-17-2009, 07:18 PM

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