i have assigned my two variables correctly, but if i try to login as soon as i enter username and jump to password textbox the username disappers from its textbox and all the credentials are not picked up as soon as i click log in command button.Below is the source code.
Option Explicit
Dim logintime As Variant
Dim logouttime As Variant
Dim sessionduration As Variant
Private Sub cmdcancel_Click()
Dim username As String
Dim password As String
username = txtuser.Text
password = txtpass.Text
txtuser.Text = ""
txtpass.Text = ""
txtuser.SetFocus
marshallmumbure@ yahoo.co.uk
End Sub
Private Sub cmdexit_Click()
'Find the ending time, compute the elapsed time
'Put both values in label boxes
logouttime = Now
sessionduration = logouttime - logintime
lbllogout.Caption = Format(logouttime, "hh:mm:ss")
lblsessiontime.Caption = Format(sessionduration, "hh:mm:ss")
MsgBox ("You are about to Log Off the System"), vbYesNo
If MsgBox("You are about to Log Off the System") = vbYes Then
frmsplashscreen.Show
frmlogin.Hide
frmsplashscreen.Show
Else
If MsgBox("You are about to Log Off the System") = vbNo Then
lblsessiontime = ""
End If
End If
End
End Sub
Private Sub cmdhelp_Click()
MsgBox ("To login, one has to enter correct USERNAME AND PASSWORD"), vbOKOnly, "Help"
txtuser.Text = ""
txtpass.Text = ""
txtuser.SetFocus
End Sub
Private Sub cmdlogin_Click()
Dim username As String
Dim password As String
Dim sessionnum As Integer
username = txtuser.Text
password = txtpass.Text
'Establish and print starting time
logintime = Now
lbllogin.Caption = Format(logintime, "hh:mm:ss")
lbllogout.Caption = ""
lblsessiontime.Caption = ""
sessionnum = 0
If username = "administrator" And password = "pass1" Then
MsgBox ("You have successfully logged in"), vbInformation + vbOKOnly, "Valid User"
sessionnum = 1 + 1
lblsessionnum = sessionnum
frmmainmenu.Show
frmlogin.Hide
Else
If username = "supervisor" And password = "pass12" Then
MsgBox ("You have successfully logged in."), vbInformation + vbOKOnly, "Valid User"
frmmainmenu.Show
Else
If username = "video club attender1" And password = "pass123" Then
MsgBox ("You have successfully logged in."), vbInformation + vbOKOnly, "Valid User"
frmmainmenu.cmddvdrentals.Visible = False
frmmainmenu.cmddvdstock.Visible = False
frmmainmenu.cmddvdnewrelease.Visible = False
frmmainmenu.cmdtaperentals.Visible = True
frmmainmenu.cmdtapestock.Visible = True
frmmainmenu.cmdtapenewrelease.Visible = True
frmmainmenu.Show
Else
If username = "video club attender2" And password = "pass1234" Then
MsgBox ("You have successfully logged in."), vbInformation + vbOKOnly, "Valid User"
frmmainmenu.cmdtaperentals.Visible = False
frmmainmenu.cmdtapestock.Visible = False
frmmainmenu.cmdtapenewrelease.Visible = False
frmmainmenu.cmddvdrentals.Visible = True
frmmainmenu.cmddvdstock.Visible = True
frmmainmenu.cmddvdnewrelease.Visible = True
frmmainmenu.Show
Else
MsgBox ("To login to the system you have to enter valid credentials,namelly USERNAME and PASSWORD."), vbInformation + vbOKOnly, "Invalid User"
lbllogin.Caption = ""
lblpass.Caption = ""
txtuser.SetFocus
End If
End If
End If
End If
End Sub