Link to home
Start Free TrialLog in
Avatar of AlexPonnath
AlexPonnathFlag for United States of America

asked on

User Right Control in an App

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"
                frm2.Show()


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
            Me.Dispose()
        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 frm.show() that way i could
work arround my problem
Avatar of BadgerBill
BadgerBill

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.
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 frm.show() 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
  frmYourForm.Show()
End If

HTH
David
Avatar of AlexPonnath

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of doobdave
doobdave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial