User Right Control in an App

Posted on 2005-05-09
Last Modified: 2010-04-23
I have an App which has a MDI main form and several children. The children are opened
from the menu of the MDI form like this:

Case "Nbr Pool List"    ' ButtonTool
                ' Place code here
                Dim frm2 As New frmnbrAllocationList
                frm2.MdiParent = Me
                frm2.Text = "Nbr Pool List"

Now everytime someone opens a form i check what rights they have like below

URstring = (UserRights(gstrUserID, Me.Name))

        URread = Trim(URstring.Substring(0, 1))
        If URread = 0 Then
        End If

My problem now is that i want to prevent the user from opening the form if he does not have the rights ? So in case
URread = 0 i want to prevent the form from opening at all. Buty since i dispose the form the code which opens the
form in the menu complains once it gets to frm2.Show() since the form has been disposed. So is there a better
way to do this ? I want to avoid querying at the calling code since there is many places which could call a form and
it is easyer to manage it  when the form loads..

Also is there a way to check if a form has been disposed before i call the that way i could
work arround my problem
Question by:AlexPonnath
    LVL 1

    Expert Comment

    The solution I think would be to have a common form open routine called from all the menu's (indeed anything that opens a form). So from your menu code you would call 'OpenForm "frmnbrAllocationList"', the routine would then first check access rights before opening the form.
    LVL 8

    Expert Comment

    Agree with BadgerBill,

    with regards your second point:

    "Also is there a way to check if a form has been disposed before i call the that way i could
    work arround my problem"

    You can check to see if the object is an instance before attempting to call any methods or functions on it, as follows:

    If Not IsNothing(frmYourForm) Then
    End If


    Author Comment

    But how does this work in an MDI enviorment where the user can open
    multiple instances of the same form. How do i check if the correct instance
    of the form has not been disposed.
    LVL 8

    Accepted Solution

    To clarify on my last post:
    frmYourForm is the name of the INSTANCE of a form, rather than the actual form CLASS.

    However, havnig looked at your post again, I now see it in a different light.

    Is this code:
    URstring = (UserRights(gstrUserID, Me.Name))

            URread = Trim(URstring.Substring(0, 1))
            If URread = 0 Then
            End If

    in your "frmnbrAllocationList" class code?
    If so, I suggest you do the rights checking in the code that creates the form, so that it only gets instantiated IF the rights are correct.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now