Hi All,
I am trying to set up permissions on forms useing code I have found in some posts here.
What I have so far works up to a point. I can login useing the correct login name and password. When I get to the "ReferralsMainReferralForm" the welcome controls shows the login users name but it does not show the user type.
strWelcome = "Welcome, " & User.strUsrFirst (This part works)
strUserID = "User Type, " & User.lngUsrType (This part does not work)
The strUserID always shows "0"
If anyone can help with this, Please
Kind Regards
Dereck
This is what I have so far.
++++++++++++++++++++
TABLE: tblUser
FIELD:strUsrFrstName (Text)
FIELD:strUsrLastName (Text)
FIELD:lngUsrType (Number)
FIELD:strUsrLogin (Text)
FIELD:strUsrPsswd (Text)
++++++++++++++++++++
I Have 2 user in the table, 1 with the lngUsrType of "1" and the other as "2".
I have a Module with the following:
I am trying to set up permissions on forms useing code I have found in some posts here.
What I have so far works up to a point. I can login useing the correct login name and password. When I get to the "ReferralsMainReferralForm" the welcome controls shows the login users name but it does not show the user type.
strWelcome = "Welcome, " & User.strUsrFirst (This part works)
strUserID = "User Type, " & User.lngUsrType (This part does not work)
The strUserID always shows "0"
If anyone can help with this, Please
Kind Regards
Dereck
This is what I have so far.
++++++++++++++++++++
TABLE: tblUser
FIELD:strUsrFrstName (Text)
FIELD:strUsrLastName (Text)
FIELD:lngUsrType (Number)
FIELD:strUsrLogin (Text)
FIELD:strUsrPsswd (Text)
++++++++++++++++++++
I Have 2 user in the table, 1 with the lngUsrType of "1" and the other as "2".
I have a Module with the following:
Code:
Option Compare Database
++++++++++++++++++++
Option Explicit
Public Type UserInfo
lngUsrId As Long
strUsrPsswd As String
strUsrFirst As String
lngUsrType As Long
ysnUsrActive As Boolean
End Type
Public User As UserInfo
++++++++++++++++++++
I have a Login Page with FIELDS for user name and password. There is an OK button with the following code behind:
++++++++++++++++++++
Private Sub cmdLogOk_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT * FROM tblUsers WHERE [lngUsrId] = " & Me.cboLogin.Value
'CHECKING FOR NULLS
If IsNull(Me.cboLogin) Then
MsgBox Mssg1, vbCritical, Title1
Me.cboLogin.SetFocus
Call CheckLogAttempts
ElseIf IsNull(Me.txtPsswd) Then
MsgBox Mssg1, vbCritical, Title1
Me.txtPsswd.SetFocus
Call CheckLogAttempts
'VALIDATING PASSWORD
Else
If Me.txtPsswd.Value = DLookup("strUsrPsswd", "tblUsers", "[lngUsrId]=" & Me.cboLogin.Value) Then
'PASSING VARIABLES TO DB
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With User
.strUsrFirst = rst.Fields("strUsrFrstName")
End With
rst.Close
'CLOSSING LOGON FORM
DoCmd.Close acForm, "frmLogon", acSaveYes
DoCmd.OpenForm "frmSplash"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPsswd.SetFocus
Call CheckLogAttempts
End If
End If
End Sub
++++++++++++++++++++
The login page runs with no errors and the frmSplash form loads.
On the frmSplash form there are the following:
++++++++++++++++++++
Private Sub Form_Load()
'GETTING VARIABLE FOR FORM
Me.txtWelcomeMssg = "Welcome, " & User.strUsrFirst
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "ReferralsMainReferralForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
Private Sub Form_Timer()
Static intCount As Integer
intCount = intCount + 40
ctlProgBar.Value = intCount
If intCount = 4000 Then
DoCmd.Close acForm, "frmSplash", acSaveYes
End If
End Sub
++++++++++++++++++++
The Timer event run and then loads "ReferralsMainReferralForm" form.
On the "ReferralsMainReferralForm" form I have a Onload procedure:
++++++++++++++++++++
Private Sub Form_Load()
Dim strWelcome As String
Dim strUserID As String
strUserID = "User Type, " & User.lngUsrType
strWelcome = "Welcome, " & User.strUsrFirst
DoCmd.Maximize
Me.txtUser = strUserID
Me.txtWelcomeMssg = strWelcome
DoCmd.GoToControl "Combo304"
End Sub
++++++++++++++++++++
There is a subform "ReferralDoctorsSubForm" and this form as an OnLoad procedure:
++++++++++++++++++++
Private Sub Form_Load()
If lngUsrType = 1 Then
Me.Form.AllowAdditions = True
Me.Form.AllowDeletions = True
Me.Form.AllowEdits = True
Else
Me.Form.AllowAdditions = False
Me.Form.AllowDeletions = False
Me.Form.AllowEdits = False
End If
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Number, Err.Description
Resume Exit_Form_Open
End Sub
++++++++++++++++++++
Last edited by a moderator: