Help with Sub-form Design (1 Viewer)

spectrolab

Registered User.
Local time
Tomorrow, 03:45
Joined
Feb 9, 2005
Messages
116
Hi all,

I am tryng to make a form with a sub-fom in the header, all pretty easty so far. The subform is a login form with a username and password control and a command button "LOGIN" with the follwoing code:

Code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEmpID) Or Me.cboEmpID = "" Then
      MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.cboEmpID.SetFocus
        Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
      MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.txtPassword.SetFocus
        Exit Sub
    End If

    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("Password", "tblEmployees", _
            "[EmpID]=" & Me.cboEmpID.Value) Then

        EmpID = Me.cboEmpID.Value

        'Close logon form and open splash screen

        Forms!frmLogin.Visible = False
        DoCmd.OpenForm "frmLIMSMainMenu"
    'DoCmd.OpenForm "frmInactiveShutDown", , , , , acHidden
    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If


End Sub

What I am trying to do, and I hope it is easy, is to restrict the command buttons in the detail section to only be 'clickable' if the login username and password are correct. The code above is when the sub-form is standalone, which works ok, but woud be better in the form that it opens "frmLIMSMainMenu". Or, am going about this completely wrong?
 

ShaneMan

Registered User.
Local time
Today, 12:45
Joined
May 9, 2005
Messages
1,224
Hi all,

I am tryng to make a form with a sub-fom in the header, all pretty easty so far. The subform is a login form with a username and password control and a command button "LOGIN" with the follwoing code:

Code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEmpID) Or Me.cboEmpID = "" Then
      MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
        Me.cboEmpID.SetFocus
        Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
      MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.txtPassword.SetFocus
        Exit Sub
    End If

    'Check value of password in tblEmployees to see if this
    'matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("Password", "tblEmployees", _
            "[EmpID]=" & Me.cboEmpID.Value) Then

        EmpID = Me.cboEmpID.Value

        'Close logon form and open splash screen

        [COLOR="Red"]Forms!frmLogin.Form.Visible = False
        Forms![frmName]![cmdButton].Enabled = True[/COLOR]
    'DoCmd.OpenForm "frmInactiveShutDown", , , , , acHidden
    Else
      MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If


End Sub

What I am trying to do, and I hope it is easy, is to restrict the command buttons in the detail section to only be 'clickable' if the login username and password are correct. The code above is when the sub-form is standalone, which works ok, but woud be better in the form that it opens "frmLIMSMainMenu". Or, am going about this completely wrong?

Hey spectrolab,

If I'm following you correctly then all you would need to do is set all the cmdButtons Enabled properties to False then all then add the lines of code in red above to your code. If you have more than one cmdButton then repeat the code of setting their Enabled properties to True.

HTH,
Shane
 

Users who are viewing this thread

Top Bottom