VERSION 5.00
Begin VB.Form frmLogin 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Login"
   ClientHeight    =   1575
   ClientLeft      =   2835
   ClientTop       =   3480
   ClientWidth     =   3750
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   105
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   250
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtUserName 
      Height          =   345
      HideSelection   =   0   'False
      Left            =   1290
      TabIndex        =   0
      Top             =   135
      Width           =   2325
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "OK"
      Default         =   -1  'True
      Height          =   390
      Left            =   720
      TabIndex        =   2
      Top             =   1080
      Width           =   1140
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "Cancel"
      Height          =   390
      Left            =   2160
      TabIndex        =   3
      Top             =   1080
      Width           =   1140
   End
   Begin VB.TextBox txtPassword 
      Height          =   345
      IMEMode         =   3  'DISABLE
      Left            =   1290
      PasswordChar    =   "*"
      TabIndex        =   1
      Top             =   525
      Width           =   2325
   End
   Begin VB.Label lblLabels 
      Caption         =   "&User Name:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   270
      Index           =   0
      Left            =   105
      TabIndex        =   4
      Top             =   150
      Width           =   1080
   End
   Begin VB.Label lblLabels 
      Caption         =   "&Password:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   270
      Index           =   1
      Left            =   240
      TabIndex        =   5
      Top             =   540
      Width           =   960
   End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit


Public Con As ADODB.Connection
Public RS As New Recordset



Private Sub cmdCancel_Click()
    Unload Me
    End
End Sub

Private Sub cmdOK_Click()
    On Error Resume Next
    'Make connection with database
    Call MainCon
    Set RS = New ADODB.Recordset
    'Make sure the user typed in the username and password
        If Trim$(txtUserName.Text) = "" Then
            MsgBox "Please enter user name and password", vbCritical, "Missing Username"
        ElseIf txtPassword.Text = "" Then
            MsgBox "Please enter user name and password", vbCritical, "Missing Password"
        End If
    'Store username and password into variables
    User = txtUserName.Text
    Pwd = txtPassword.Text
    frmLogin.MousePointer = vbHourglass
    'Open database and search for user info
    RS.Open ("SELECT * FROM Users WHERE username = '" & User & "'"), Con, adOpenStatic, adLockOptimistic, adCmdText
    'If not found in the database, inform user
        If RS.EOF Then
            MsgBox "User not found", vbCritical, "Incorrect Login"
            txtPassword.Text = ""
            txtUserName.SetFocus
            SendKeys "{Home}+{End}"
            txtUserName.SelLength = Len(txtUserName.Text)
            frmLogin.MousePointer = vbNormal
            Exit Sub
        End If
    'If the user typed in the wrong password, inform user
        If RS.Fields("password") <> Pwd Then
            MsgBox "Incorrect password " & vbCrLf & "Please try again", vbCritical, "Incorrect Login"
            txtPassword.Text = ""
            txtPassword.SetFocus
            frmLogin.MousePointer = vbNormal
        Else
    'If everything else checks out, log in to main screen
            RS.Close
            frmLogin.MousePointer = vbNormal

            Unload Me
            frmMain.Visible = True
            frmMain.Show
        End If
        Con.Close
End Sub


Private Sub Form_Load()
    If App.PrevInstance Then Unload Me

End Sub


Private Sub txtPassword_GotFocus()
    txtPassword.SelLength = Len(txtPassword.Text)
    
End Sub

Private Sub txtUserName_GotFocus()
    txtUserName.SelLength = Len(txtUserName.Text)
End Sub




Public Sub MainCon()
    Set Con = New ADODB.Connection
    Con.CursorLocation = adUseClient
    Con.Provider = "Microsoft.Jet.OLEDB.4.0"
    Con.Properties("Data Source") = App.Path & "\EmpLic.mdb"
    Con.Open
    


End Sub

