2ede Sikh Philosophy Network - View Single Post - Disenabling buttons base on User
View Single Post
  #6 (permalink)  
Old 28-Jul-2006, 08:21 AM
Rob Parker's Avatar Rob Parker
Guest
 
Posts: n/a
   
   
Re: Disenabling buttons base on User

There are several possible approaches to this problem. The best, or
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/11469-disenabling-buttons-base-on-user.html
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
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11469
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" 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.



Reply With Quote
 
Page generated in 0.16441 seconds with 25 queries
0