Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Disenabling buttons base on User

Discussion in 'Information Technology' started by dcash45, Jul 28, 2006.

  1. dcash45

    dcash45
    Expand Collapse
    Guest

    Hello I want to open a form and enable or disenable the buttons base on what
    type of user is login.

    I have a login form that goes to two different switchboard forms base on the
    type of user (manage or employee). But both switchboard calls on some of the
    same form; like my states form. This form has the buttons of Add, Update,
    Delete, and so on. The manager would have the right to do all of the
    functions but I want the employees to only have the right to just Update. So
    if an employee login and opening the states form I want the Add and Delete
    button to be disenable and if a manage login all the buttons stay enable.

    So I would like to know does anyone know how to design is code because I am
    having some problems designing it.

    Thank you,
     
  2. Rob Parker

    Rob Parker
    Expand Collapse
    Guest

    Since you can already determine whether the type of user, I'll assume that
    you have a function (IsManager in the following lines) that returns True if
    the user is a manager.

    In the Open event of your form(s), you can enable/disable various controls
    as follows:

    Me.MyAddButtonName.Enabled = IsManager

    You can also set the form properties to allow edits/additions/deletes in the
    same fashion:

    Me.AllowEdits = IsManager

    HTH,

    Rob


    "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    news:F56D15D9-ABC1-48F4-AAC4-B61306A775F6@microsoft.com...
    > Hello I want to open a form and enable or disenable the buttons base on
    > what
    > type of user is login.
    >
    > I have a login form that goes to two different switchboard forms base on
    > the
    > type of user (manage or employee). But both switchboard calls on some of
    > the
    > same form; like my states form. This form has the buttons of Add, Update,
    > Delete, and so on. The manager would have the right to do all of the
    > functions but I want the employees to only have the right to just Update.
    > So
    > if an employee login and opening the states form I want the Add and Delete
    > button to be disenable and if a manage login all the buttons stay enable.
    >
    > So I would like to know does anyone know how to design is code because I
    > am
    > having some problems designing it.
    >
    > Thank you,
    >
     
  3. dcash45

    dcash45
    Expand Collapse
    Guest

    Hi Rob thanks for replying but Im still a little lost. Yos said I should have
    a IsManager function but I didnt have one. So I designing it right now but I
    dont really know what I should include.

    "Rob Parker" wrote:

    > Since you can already determine whether the type of user, I'll assume that
    > you have a function (IsManager in the following lines) that returns True if
    > the user is a manager.
    >
    > In the Open event of your form(s), you can enable/disable various controls
    > as follows:
    >
    > Me.MyAddButtonName.Enabled = IsManager
    >
    > You can also set the form properties to allow edits/additions/deletes in the
    > same fashion:
    >
    > Me.AllowEdits = IsManager
    >
    > HTH,
    >
    > Rob
    >
    >
    > "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    > news:F56D15D9-ABC1-48F4-AAC4-B61306A775F6@microsoft.com...
    > > Hello I want to open a form and enable or disenable the buttons base on
    > > what
    > > type of user is login.
    > >
    > > I have a login form that goes to two different switchboard forms base on
    > > the
    > > type of user (manage or employee). But both switchboard calls on some of
    > > the
    > > same form; like my states form. This form has the buttons of Add, Update,
    > > Delete, and so on. The manager would have the right to do all of the
    > > functions but I want the employees to only have the right to just Update.
    > > So
    > > if an employee login and opening the states form I want the Add and Delete
    > > button to be disenable and if a manage login all the buttons stay enable.
    > >
    > > So I would like to know does anyone know how to design is code because I
    > > am
    > > having some problems designing it.
    > >
    > > Thank you,
    > >

    >
    >
    >
     
  4. Rob Parker

    Rob Parker
    Expand Collapse
    Guest

    In your first post, you said " ... goes to two different switchboard forms
    base on the type of user (manage or employee)." Therefore, you already have
    some means of identifying which type of user is logged in. How are you
    doing that? Please post the code you are using for that, and we'll go from
    there.

    Rob

    "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    news:8D10EBCA-EE89-46B6-9A8F-8E5A2DE86B0A@microsoft.com...
    > Hi Rob thanks for replying but Im still a little lost. Yos said I should
    > have
    > a IsManager function but I didnt have one. So I designing it right now
    > but I
    > dont really know what I should include.
    >
    > "Rob Parker" wrote:
    >
    >> Since you can already determine whether the type of user, I'll assume
    >> that
    >> you have a function (IsManager in the following lines) that returns True
    >> if
    >> the user is a manager.
    >>
    >> In the Open event of your form(s), you can enable/disable various
    >> controls
    >> as follows:
    >>
    >> Me.MyAddButtonName.Enabled = IsManager
    >>
    >> You can also set the form properties to allow edits/additions/deletes in
    >> the
    >> same fashion:
    >>
    >> Me.AllowEdits = IsManager
    >>
    >> HTH,
    >>
    >> Rob
    >>
    >>
    >> "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    >> news:F56D15D9-ABC1-48F4-AAC4-B61306A775F6@microsoft.com...
    >> > Hello I want to open a form and enable or disenable the buttons base on
    >> > what
    >> > type of user is login.
    >> >
    >> > I have a login form that goes to two different switchboard forms base
    >> > on
    >> > the
    >> > type of user (manage or employee). But both switchboard calls on some
    >> > of
    >> > the
    >> > same form; like my states form. This form has the buttons of Add,
    >> > Update,
    >> > Delete, and so on. The manager would have the right to do all of the
    >> > functions but I want the employees to only have the right to just
    >> > Update.
    >> > So
    >> > if an employee login and opening the states form I want the Add and
    >> > Delete
    >> > button to be disenable and if a manage login all the buttons stay
    >> > enable.
    >> >
    >> > So I would like to know does anyone know how to design is code because
    >> > I
    >> > am
    >> > having some problems designing it.
    >> >
    >> > Thank you,
    >> >

    >>
    >>
    >>
     
  5. dcash45

    dcash45
    Expand Collapse
    Guest

    I have a user type table thats keeps the usertypeId & usertypename. I have
    another that call login which links the userID & the usertypeID together. So
    in the form login the code I use is .....

    Sub procLogin(UserName As String, Pwd As String)
    On Error GoTo LoginErrors

    ' Declare variables
    Dim dbsConnection As Database
    Dim rsUser As Recordset
    Dim dbstring As String
    Dim sqlString As String
    Dim thisUser As String
    Dim temp As Integer

    ' DFD 1.3 (DBU1)
    ' Connect to database by calling a module procedure.
    Set dbsConnection = procConnectToDatabase()

    ' Define and open the table
    sqlString = "tblLogin"
    Set rsUser = dbsConnection.OpenRecordset(sqlString)

    sqlString = "SELECT tblLogin.UserID, tblLogin.Username,
    tblLogin.Password, tblLogin.UserTypeID" & _
    " FROM tblLogin" & _
    " WHERE (((tblLogin.Username)='" & UserName & "') AND
    ((tblLogin.Password)='" & Pwd & "'));"



    ' Send the SQL Query to the database connection
    Set rsUser = dbsConnection.OpenRecordset(sqlString)

    ' if eof then user was found with that username/ password
    If rsUser.EOF Then
    temp = MsgBox("Invalid Login.", vbExclamation, "Can't Log In")
    ' DFD 1.5
    ' close recordsets and database connection
    rsUser.Close
    'Call procCloseDatabase(dbsConnection)
    Exit Sub

    'DFD 1.6
    Else
    ' User found so find out what type they are and display appropriate GUI
    UserTypeID = rsUser!UserTypeID

    ' Close Login GUI
    DoCmd.Close

    Select Case UserTypeID

    Case 1: ' Manager logged in, open Manager Switchboard GUI
    DoCmd.OpenForm "frmManagerSwitchboard", , , , , , rsUser!userID
    Case 2: ' Employee switchboard Logged In, open Employee switchboard GUI
    DoCmd.OpenForm "frmEmployeeSwitchboard", , , , , , rsUser!userID
    Case 3: ' Customer switchboard Logged In, open Customer switchboard GUI
    DoCmd.OpenForm "frmCustomerSwitchboard", , , , , , rsUser!userID
    Case Else: procDisplayMessage ("You are not authorized to login")

    End Select


    so now after the user is login a switchboard display depending the type of
    user and in this switchboard I have buttons that opening up other forms. Now
    the manager switcbhoard and the employee switchboard is different but the 2
    have a button that opens up the form states...now heres where I get lost. I
    dont know how to enable or disenable the buttons base on the user.
     
  6. Rob Parker

    Rob Parker
    Expand Collapse
    Guest

    There are several possible approaches to this problem. The best, or
    feasible, one will depend on how the application works after the switchboard
    form is opened, and perhaps on whether the application is split, with each
    user having their own front-end and a shared back-end datafile. [Note: I'm
    assuming from your current code that you are not using Access's built-in
    user-level security.]

    First off, I suggest using a function based on whether the manager
    switchboard was opened, which will work providing the switchboard form is
    not closed until the user ends the session. The switchboard can be hidden
    when other forms are opened form it (that's a very common practice), and
    this will still work. Copy the following into a module, and save the
    module - you must give it a different name to that of this function!

    Public Function IsManager() As Boolean
    Dim i As Integer
    IsManager = False
    For i = 0 To Forms().Count - 1
    If Forms(i).Name = "frmManagerSwitchboard" Then IsManager = True
    Next i
    End Function

    This returns True or False, depending on whether the frmManagerSwitchboard
    is open or not; it uses the fact that a form which is not open is not a
    member of the Forms collection. This function will allow the statements I
    posted previously to work.

    If this doesn't work, post again and we'll explore further alternatives.

    HTH,

    Rob


    "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    news:38C87C06-A8AA-427E-8544-C9D5D27693A7@microsoft.com...
    >I have a user type table thats keeps the usertypeId & usertypename. I have
    > another that call login which links the userID & the usertypeID together.
    > So
    > in the form login the code I use is .....
    >
    > Sub procLogin(UserName As String, Pwd As String)
    > On Error GoTo LoginErrors
    >
    > ' Declare variables
    > Dim dbsConnection As Database
    > Dim rsUser As Recordset
    > Dim dbstring As String
    > Dim sqlString As String
    > Dim thisUser As String
    > Dim temp As Integer
    >
    > ' DFD 1.3 (DBU1)
    > ' Connect to database by calling a module procedure.
    > Set dbsConnection = procConnectToDatabase()
    >
    > ' Define and open the table
    > sqlString = "tblLogin"
    > Set rsUser = dbsConnection.OpenRecordset(sqlString)
    >
    > sqlString = "SELECT tblLogin.UserID, tblLogin.Username,
    > tblLogin.Password, tblLogin.UserTypeID" & _
    > " FROM tblLogin" & _
    > " WHERE (((tblLogin.Username)='" & UserName & "') AND
    > ((tblLogin.Password)='" & Pwd & "'));"
    >
    >
    >
    > ' Send the SQL Query to the database connection
    > Set rsUser = dbsConnection.OpenRecordset(sqlString)
    >
    > ' if eof then user was found with that username/ password
    > If rsUser.EOF Then
    > temp = MsgBox("Invalid Login.", vbExclamation, "Can't Log In")
    > ' DFD 1.5
    > ' close recordsets and database connection
    > rsUser.Close
    > 'Call procCloseDatabase(dbsConnection)
    > Exit Sub
    >
    > 'DFD 1.6
    > Else
    > ' User found so find out what type they are and display appropriate GUI
    > UserTypeID = rsUser!UserTypeID
    >
    > ' Close Login GUI
    > DoCmd.Close
    >
    > Select Case UserTypeID
    >
    > Case 1: ' Manager logged in, open Manager Switchboard GUI
    > DoCmd.OpenForm "frmManagerSwitchboard", , , , , , rsUser!userID
    > Case 2: ' Employee switchboard Logged In, open Employee switchboard GUI
    > DoCmd.OpenForm "frmEmployeeSwitchboard", , , , , ,
    > rsUser!userID
    > Case 3: ' Customer switchboard Logged In, open Customer switchboard GUI
    > DoCmd.OpenForm "frmCustomerSwitchboard", , , , , ,
    > rsUser!userID
    > Case Else: procDisplayMessage ("You are not authorized to login")
    >
    > End Select
    >
    >
    > so now after the user is login a switchboard display depending the type of
    > user and in this switchboard I have buttons that opening up other forms.
    > Now
    > the manager switcbhoard and the employee switchboard is different but the
    > 2
    > have a button that opens up the form states...now heres where I get lost.
    > I
    > dont know how to enable or disenable the buttons base on the user.
     
  7. dcash45

    dcash45
    Expand Collapse
    Guest

    Thanks Rob I will work on it and let you know if this helps me out.

    "Rob Parker" wrote:

    > There are several possible approaches to this problem. The best, or
    > feasible, one will depend on how the application works after the switchboard
    > form is opened, and perhaps on whether the application is split, with each
    > user having their own front-end and a shared back-end datafile. [Note: I'm
    > assuming from your current code that you are not using Access's built-in
    > user-level security.]
    >
    > First off, I suggest using a function based on whether the manager
    > switchboard was opened, which will work providing the switchboard form is
    > not closed until the user ends the session. The switchboard can be hidden
    > when other forms are opened form it (that's a very common practice), and
    > this will still work. Copy the following into a module, and save the
    > module - you must give it a different name to that of this function!
    >
    > Public Function IsManager() As Boolean
    > Dim i As Integer
    > IsManager = False
    > For i = 0 To Forms().Count - 1
    > If Forms(i).Name = "frmManagerSwitchboard" Then IsManager = True
    > Next i
    > End Function
    >
    > This returns True or False, depending on whether the frmManagerSwitchboard
    > is open or not; it uses the fact that a form which is not open is not a
    > member of the Forms collection. This function will allow the statements I
    > posted previously to work.
    >
    > If this doesn't work, post again and we'll explore further alternatives.
    >
    > HTH,
    >
    > Rob
    >
    >
    > "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    > news:38C87C06-A8AA-427E-8544-C9D5D27693A7@microsoft.com...
    > >I have a user type table thats keeps the usertypeId & usertypename. I have
    > > another that call login which links the userID & the usertypeID together.
    > > So
    > > in the form login the code I use is .....
    > >
    > > Sub procLogin(UserName As String, Pwd As String)
    > > On Error GoTo LoginErrors
    > >
    > > ' Declare variables
    > > Dim dbsConnection As Database
    > > Dim rsUser As Recordset
    > > Dim dbstring As String
    > > Dim sqlString As String
    > > Dim thisUser As String
    > > Dim temp As Integer
    > >
    > > ' DFD 1.3 (DBU1)
    > > ' Connect to database by calling a module procedure.
    > > Set dbsConnection = procConnectToDatabase()
    > >
    > > ' Define and open the table
    > > sqlString = "tblLogin"
    > > Set rsUser = dbsConnection.OpenRecordset(sqlString)
    > >
    > > sqlString = "SELECT tblLogin.UserID, tblLogin.Username,
    > > tblLogin.Password, tblLogin.UserTypeID" & _
    > > " FROM tblLogin" & _
    > > " WHERE (((tblLogin.Username)='" & UserName & "') AND
    > > ((tblLogin.Password)='" & Pwd & "'));"
    > >
    > >
    > >
    > > ' Send the SQL Query to the database connection
    > > Set rsUser = dbsConnection.OpenRecordset(sqlString)
    > >
    > > ' if eof then user was found with that username/ password
    > > If rsUser.EOF Then
    > > temp = MsgBox("Invalid Login.", vbExclamation, "Can't Log In")
    > > ' DFD 1.5
    > > ' close recordsets and database connection
    > > rsUser.Close
    > > 'Call procCloseDatabase(dbsConnection)
    > > Exit Sub
    > >
    > > 'DFD 1.6
    > > Else
    > > ' User found so find out what type they are and display appropriate GUI
    > > UserTypeID = rsUser!UserTypeID
    > >
    > > ' Close Login GUI
    > > DoCmd.Close
    > >
    > > Select Case UserTypeID
    > >
    > > Case 1: ' Manager logged in, open Manager Switchboard GUI
    > > DoCmd.OpenForm "frmManagerSwitchboard", , , , , , rsUser!userID
    > > Case 2: ' Employee switchboard Logged In, open Employee switchboard GUI
    > > DoCmd.OpenForm "frmEmployeeSwitchboard", , , , , ,
    > > rsUser!userID
    > > Case 3: ' Customer switchboard Logged In, open Customer switchboard GUI
    > > DoCmd.OpenForm "frmCustomerSwitchboard", , , , , ,
    > > rsUser!userID
    > > Case Else: procDisplayMessage ("You are not authorized to login")
    > >
    > > End Select
    > >
    > >
    > > so now after the user is login a switchboard display depending the type of
    > > user and in this switchboard I have buttons that opening up other forms.
    > > Now
    > > the manager switcbhoard and the employee switchboard is different but the
    > > 2
    > > have a button that opens up the form states...now heres where I get lost.
    > > I
    > > dont know how to enable or disenable the buttons base on the user.

    >
    >
    >
     
  8. dcash45

    dcash45
    Expand Collapse
    Guest

    Hi from what I can tell it seen to be working but Im still going to test if
    fully to make sure it working the may I want it to...But thanks a whole lot...
     
  9. Rob Parker

    Rob Parker
    Expand Collapse
    Guest

    You're welcome. And there's no such a thing as too much testing ;-)

    Rob

    "dcash45" <dcash45@discussions.microsoft.com> wrote in message
    news:DC628D66-EF78-44F8-9F14-A1765761F35B@microsoft.com...
    > Hi from what I can tell it seen to be working but Im still going to test
    > if
    > fully to make sure it working the may I want it to...But thanks a whole
    > lot...
     

Share This Page