Solved

Login Code

Posted on 2000-05-13
3
154 Views
Last Modified: 2010-05-02
This is probably a very simple problem,
but being a true novice to the VB programming I can't seem to get this to work.
I am trying to write a simple Login code. You type in a username & password
for validation. You have 3 chances to
get it right.If you type in the incorrect username or password a msgbox will say invalid. How can I get the code to allow 3 seperate passes and then a final msgbox saying Access denied
and end the program.
0
Comment
Question by:DavidTimonium
3 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2807598
How about adding a private variable m_MissedPasses As Integer. In the login command button you put code to check if the password is correct, if it's not then add +1 to the m_MissedPasses variable. Then use code like...

   If (m_MissedPasses = 3) Then
      MsgBox "Stupid User did not enter correct Password"
      End
   End If

....to end the program.

Actually I would not use the End statement, but that's the easy way to do it. You should use Unload Me instead, but since I do not know what your program look like I can not say exactly how it should look like.
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
ID: 2807612
Hi
You start form code:
'Place 2 textboxes and two Commandbuttons on form

Dim CorrectPass As String, CorrectName As String
Dim bOK As Boolean

Private Sub Command1_Click()
  Static nCount As Integer
  If Text1 = "" Or Text2 = "" Then
     MsgBox "Enter UserName and Password!", vbOKOnly + vbExclamation
     Exit Sub
  End If
  nCount = nCount + 1
  If nCount > 2 Then End
  If Text1 = CorrectName And Text2 = CorrectPass Then bOK = True
  If bOK Then
     MsgBox "Correct!" & vbCrLf & "Press OK to continue", vbOKOnly
     End
  Else
     MsgBox "Incorrect!" & vbCrLf & "You have " & CStr(3 - nCount) & " more chance(s)", vbOKOnly
  End If
End Sub

Private Sub Command2_Click()
  End
End Sub

Private Sub Form_Load()
  bOK = False
  Caption = "Enter username and password"
  CorrectName = "Ark"
  CorrectPass = "DavidTimonium"
  Text1 = ""
  Text2 = ""
  Text1.PasswordChar = "*"
  Text2.PasswordChar = "*"
  Command1.Caption = "&Submit"
  Command2.Caption = "&Exit"
End Sub
0
 

Author Comment

by:DavidTimonium
ID: 2807660
Thanx Ark....It worked like a charm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now