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

Recommended Answers

All 2 Replies

I don't see a reason why you are experiencing these symptoms... What OS? What SP?

Hello friend
i am new to this but i am worked with vb
in your code you are using variables but there is less variables for me.I will test your code but ...
Is there is any code in your txtuser.Text ?
I think you given login name and password in coding.Normally i am using database to login.
I think it is better to use database in creating login form [ it will reduce that bigggggggggggggggg code ]
It is easy to create database login , in vb6 its look like an instant database connection.

If you are interested i will give my code.Now here is my way ....

For this i need 4 text boxes and 1 data control and one user database.
Text1 for typing the username
Text2 for typing the password
Text3 is a hidden text box which contains the username from the user database.
Text4 is also a hidden text box which contains the user password from the user database.
Data1 and set the ' data source ' to user database.

Set the " DATA SOURCE " to Data1 in properties of Text 3 & 4 and data filed values to ' User database ' username and user password.
Users can enter the username in Text1.If such username found in the user database then his password will load to Text4.When you click the LOGIN button then it will compare the PASSWORD text Text2 with Text4 , if both text are same then you can log in .
It will work [ i am using this way for years ].

In database you can also add Password hints for different user and authorized users can create , edit users and many user controls.

And one more i saw your message box code it looks like

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

I am using totally differentcode :

'variables for message boxes
Dim msgtxt As String
Dim msgformat As String
Dim msgtitle As String
Dim msgans As String

Private Sub cmdClose_Click()
msgtxt = "Are you sure do you want to exit ? "
msgformat = vbCritical + vbYesNo
msgtitle = "Close ..."
msgans = MsgBox(msgtxt, msgformat, msgtitle)

If msgans = vbYes Then
End
Else
Exit Sub
End If

End Sub
----------------------------------------------------------------

Try it ....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.