Results 1 to 7 of 7
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Need to Adjust Form based on User

    Hello All,



    I have a Login Form that check to see what User Type the person logged in has and opens another form and closes the Log in Form. What I want to do is based on that users User Type I want to show or hide subforms that are on the form that opens.

    Here is a section of the code I am using.

    If rs!UserType = 7 Then 'Checks to what user Priviledges User Has, opens frmMain
    CurrentDb.Properties("AllowBypassKey") = False
    DoCmd.Close acForm, "frmMain"
    DoCmd.Close acForm, "frmLoginScreen"


    I also want to be able to position the height of the subform based on the Used type

    Can someone let me know how to add code to do this?

    Thanks
    Dave

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Could save user info somewhere that can be referenced when needed. This can be a global variable, a TempVar, or a textbox. Can pass UserType to second form with OpenArgs argument of OpenForm command. Then code in second form Open event sets its properties.
    Code:
       Select Case Me.OpenArgs
          Case "this type"
             'do this
          Case "another type"
             'do this
       End Select
    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
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    June7,
    Where would I set that? I've been away from Access for at least 2 years and I am a little rusty.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I said the form Open event.

    Exactly which part of suggestion is not clear?

    Why is your code closing frmMain? Shouldn't it be opening?

    This is a common topic.
    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
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    June7,

    Yes, that was a mistake on my part which I have corrected, The code now states

    If rs!UserType = 7 Then 'Checks to what user Priviledges User Has, opens frmMain

    CurrentDb.Properties("AllowBypassKey") = False

    DoCmd.Open acForm, "frmMain"
    DoCmd.Close acForm, "frmLoginScreen"

    I set the Public Variable as follows in the frmLoginScreen

    Option Compare Database
    Option Explicit
    Public UserType As Integer

    Is this the correct location?

    Again, forgive me for not being as astute as I could be.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Public global variable would have to be declared in a general module in order for it to be available to any module. Then you populate the variable with frmLoginScreen code and use it in frmMain Open event.

    Beware, variables lose their value when code encounters unhandled run-time errors.
    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.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,944
    I used to use TempVars()
    Apparently they still exist after such errors?, but I was not aware of that at the time.
    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

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2022, 06:55 PM
  2. Replies: 3
    Last Post: 05-02-2018, 11:37 AM
  3. adjust column width in datasheet form
    By Bospeentje in forum Forms
    Replies: 3
    Last Post: 09-15-2014, 10:13 AM
  4. Replies: 4
    Last Post: 04-14-2014, 08:08 PM
  5. populate field in a form based on user???
    By DCV0204 in forum Forms
    Replies: 1
    Last Post: 01-17-2013, 08:16 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