Forms permissions useing VB Code

dcjones

Dereck
Local time
Today, 20:37
Joined
Mar 10, 2004
Messages
108
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:

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:
dcjones,

Too much code to try to run mentally.

Can you post a sample. It would be much easier with the debugger.

Tools --> Database Utilities --> Compact/Repair
Then ZIP

Wayne
 
i have the same problem with the same code can any one help:(
 
HI
I hope that you could help in this.
I am new in access.
I created few tables, one of them called Requests (RequestID, DateLogged, EndDate, StatusID, RequestSubject) Then i created a form related to this table that shows the records of this table, on the other side I created a blank form and I grabbed few controls that enables the user to fill the subject of the request and description and .. etc, and i created in that form a save button, I need when the user enters his records and press on the save button to save all the records in the Request's form.
I hope that you got me.
Thanks
 
I say: Don't use code that you can't understand and don't know how it works

Do you have a table that hold data what each user can or can't do ?
Do you have a logIn form ?
 

Users who are viewing this thread

Back
Top Bottom