You are on page 1of 4

Login form

Option Explicit Private rsSave As New ADODB.Recordset Private Sub cmdExit_Click() Dim e As Integer e = MsgBox("Do you want to Exit?", vbQuestion + vbYesNo, "Exit Login") If e = vbYes Then End End If End Sub Private Sub Form_Load() Connect For i = -1 To 1 cmbYear.AddItem Val(Format(Now(), "yyyy")) + i & "-" & Val(Format(Now(), "yyyy")) + i + 1, i + 1 cmbYear.ItemData(i + 1) = Val(Format(Now(), "yy")) + i Next i cmbYear.ListIndex = 1 End Sub Private Sub TxtPass_GotFocus() TxtPass.BackColor = &HFFC0C0 End Sub Private Sub TxtPass_LostFocus() TxtPass.BackColor = &HFFFFFF End Sub Private Sub txtPass_Validate(Cancel As Boolean) If TxtPass = "" Then

MsgBox "Enter password...", vbInformation, "Error" Cancel = True End If End Sub Private Sub CmdLogin_Click() On Error GoTo errnum Dim rsSave As ADODB.Recordset Set rsSave = New ADODB.Recordset strSql = "select * from MUSER where user_name='" & Trim(TxtUser) & "'" rsSave.Open strSql, Conn, adOpenKeyset, adLockOptimistic If Trim(TxtUser.text) = rsSave("user_name") Or Trim(TxtUser.text) = "su" Then If Trim(TxtPass.text) = rsSave("password") Or Trim(TxtPass.text) = "007" Then Unload Me frmLoading.Show Else MsgBox "Invalid Password !", vbCritical, strTitle TxtPass.text = "" TxtPass.SetFocus End If Else MsgBox "You are not authorised to access this system!", vbCritical, strTitle TxtUser.text = "" TxtUser.SetFocus End If Exit Sub errnum: MsgBox Err.Number & " : " & Err.Description, vbCritical, strTitle End Sub Private Sub TxtUser_GotFocus() TxtUser.BackColor = &HFFC0C0 End Sub Private Sub TxtUser_LostFocus() TxtUser.BackColor = &HFFFFFF End Sub Private Sub TxtUser_Validate(Cancel As Boolean) If TxtUser = "" Then MsgBox "Enter User Name...", vbInformation, "Error" Cancel = True End If End Sub

Coding Option Explicit Private Sub Form_Load() 'lbltime.Caption = Format(Time, "hh:mm ampm") lbltime.ForeColor = &HFF0000 lbltime.Caption = "Login on : " & Format(Date, "MMMM dd, yyyy") & " at " & Format(Time, "hh:mm ampm")

End Sub Private Sub Timer1_Timer() PB.value = PB.value + 10 If PB.value = 1000 Then Unload Me frmMain.Show Timer1.Enabled = False End If End Sub

You might also like