Results 1 to 3 of 3
  1. #1
    Boost is offline Advanced Beginner
    Windows 8 Access 2013 64bit
    Join Date
    May 2018
    Posts
    47

    Limiting the contents of a Combo Box // depending on USERID

    Hi there,



    I have successfully implemented a UserAccessID method that locks down various aspects of my database.

    I have a search form, that prompts the end-user to choose a query from which to conduct a 'smart search'. This combo-box gets the list of queries available using the following function in the Row Source:

    Code:
    SELECT DISTINCT MSysObjects.Name FROM MSYsObjects WHERE (((MSysObjects.Name) Like *qry_));
    In doing so, the combo box is populated by all queries in my dB that start with the prefix of "qry_".

    However, I have multiple queries that contain various collations of data records that are relatable only to certain end-users. For example, only the Manager of the Bay Area would need and want to see the query that pulls together all Bay Area data, while the Manager of SF would only need to see the query that pulls together the city data.

    Is there any way to limit the contents of a single combo box by identifying using the IF function, based on access ID - what is available/visible?

    Another way I have tried to achieve this has been to construct a combo-box for each end-user group that is available/hidden based off of the UserAccessID when they log in.

    However, my code allows for only one master combo-box to determine what query is being searched and refined - so is there a way to link the value of multiple combo boxes (of which only one can contain a value at any given time) (IE. if there are four combo boxes, only one will have a record in it) and have that value written/ported to the master combo-box which could be hidden in the background?

    The way I have set up my userAccessID's is roughly as follows:

    Code:
    Private Sub Form_Open(Cancel As Integer)    If User.AccessID = 1 Or User.AccessID = 10 Then
            Me.cboAvailableQueries.Enabled = True
            Me.cbo24.Enabled = True
            Me.cbo36.Enabled = True
            Me.cbo57.Enabled = True
            End If
    
         If User.AccessID = 7 Or User.AccessID = 11 Then
            Me.cbo57.Enabled = True
            Me.cbo24.Enabled = False
            Me.cbo36.Enabled = False
            Me.cboAvailableQueries.Enabled = False
            Exit Sub
        End If
    
        If User.AccessID = 8 Or User.AccessID = 12 Then
            Me.cbo36.Enabled = True
            Me.cbo24.Enabled = False
            Me.cbo57.Enabled = False
            Me.cboAvailableQueries.Enabled = False
            Exit Sub
        End If
    
        If User.AccessID = 9 Or User.AccessID = 13 Then
            Me.cbo24.Enabled = True
            Me.cbo36.Enabled = False
            Me.cbo57.Enabled = False
            Me.cboAvailableQueries.Enabled = False
        End If
            Exit Sub
    End Sub
    Here is an image of the form I am currently attempting to manipulate with my current attempts at figuring this out:

    Click image for larger version. 

Name:	Capture copy.jpg 
Views:	11 
Size:	204.1 KB 
ID:	35311
    Attached Thumbnails Attached Thumbnails Capture copy.jpg  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want to set RowSource property with selected SQL statement? I think combobox columns have 255 character limit so referencing column index to get SQL might not be feasible. Use the ID with DLookup to pull SQL from table. Code in each restricted combobox AfterUpdate event would set master RowSource.
    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.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    have you freetyped your rowsource? - you say

    In doing so, the combo box is populated by all queries in my dB that start with the prefix of "qry_".
    but the sql has the criteria 'Like *qry_' - which is a suffix

    That said, your issue is trying to limit what a manager sees and is available for selection in a combo. So far as I can see the easy way (although goes against 'normalisation') would be to include in your query name a key such as 'Bay' or 'SF' and have that key associated with the manager so you can include it in your rowsource criteria. But would only work for a relatively limited number of keys - at some point you are likely to get a clash.

    A more flexible way would be to use the query description property to hold the key. Then rather than using msysObjects, parse the querydefs collection to build a value list of the queries - something like


    Code:
    function getQueryNames(key as string) as string
    dim qdef as querydef
    dim qryStr as string
    
    qryStr=""
    for each qdef in currentdb.querydefs
        if qdef.description=key then qryStr=qryStr & "," & qdef.name
    
    next qdef
    
    if qryStr<>"" then getQueryNames=mid(qryStr,2)
    
    end function
    and to call (probably in the form open event if you already know the manager at that time)....

    me.combo.rowsource=getQueryNames(managerkey)

    But I would question this

    However, I have multiple queries that contain various collations of data records that are relatable only to certain end-users. For example, only the Manager of the Bay Area would need and want to see the query that pulls together all Bay Area data, while the Manager of SF would only need to see the query that pulls together the city data.
    I would expect a single query which would have appropriate filters applied to limit the rows which would mean you would not need the above

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

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2018, 03:58 PM
  2. Replies: 39
    Last Post: 03-15-2017, 07:34 PM
  3. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  4. Replies: 5
    Last Post: 12-17-2014, 10:31 AM
  5. limiting a list in a combo box
    By NoobieNoob in forum Access
    Replies: 1
    Last Post: 08-20-2013, 02:31 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