Computer Programming web Web programming Tips

Visual Basic Password Keeper Application. Part 1 - Complete VB code

By Sergey Skudaev

The VB password keeper is a Visual Basic version of The Password Keeper application which was implemented earlier in MS ACCESS. Here you will find a complete VB code. I grant it to you.

To Doanload the last version of VB Application source files

I used Windows 7 (64 bit) and had no problem with VB6 and MS Access 2000 database.I included MS Access 2000 "password.mdb" database in zip file

Please read Start Visual Basic tutorial before creating the Password Keeper Application in VB.

In MS Access create mypassword.mdb database with one table passwords. Save it in VB directory, VBPassword subdirectory. Please see tutorial how to create database in MS Access. Use MS Access 2000, since VB6 has problem with later MS Access Versions. You can create MS Access 2000 database using Visual Basic. Maybe later I give you that code. for now please find a code online.

Hover mouse over a thumbnail to see a large image.

Visual Basic Code example

Figure 1. Passwords table fields

Create VB project with two forms and one module. Enter WINMAIN name for module, frmMain name for main form and frmLogin name for login form.Save it in VB directory, VBPassword subdirectory.

Select Project, References from main menu and mark Microsoft ActiveX Data Objects library

Visual Basic, Project, References windows

Figure 2. Project. References.

Click OK button.

Select Project, Project Properties, General tab and enter project name "Password Keeper". Set Startup Object to Sub Main.

Visual Basic Code example Select Project, Project Properties

Figure 3. Project. Properties.

Click OK button

Select Tools, Options, Editor tab and mark all check boxes

Visual Basic Code example Tools, Options

Figure 4. Tools. Options.

Click OK button

Select frmLogin form. On proporties window change form caption to Login. Select icon and click a button next to it. Go to "Common\Graphics\Icons\Misc" folder and select a key or lock icon. It will display on the form title bat.

Place on frmLogin form two text controls and one command button control. In properties window enter txtLogin name for the first text control and txtPassword name for the second text control.

Visual Basic, Properties window

Select text proporty and delete default "text1" text in both text controls.

Enter cmdLogin name for command button. Enter Login caption for command button.

Place on the form three label controls: one for title "Password Keeper" and two for text field names. Change one label caption to "Login", another to "Password".

Visual Basic, Properties window

Figure 5. frmLogin form with controls.

Select WINMAIN module click Tools, Add Procedure and create public main subroutine.

VB Add Procedure and create public main subroutine

Figure 6. Sub Main procedure

Add public centre sub. Enter the following code in WINMAIN procedures:

'Declare global ADODB connection object
Public Conn As ADODB.Connection

Public Sub main()

Dim strConn As String

Set Conn = New ADODB.Connection

'Connect to database. One connection object will be used for all connections
Conn.Provider = "Microsoft.Jet.Oledb.4.0"
Conn.Open App.Path & "\mypasswords.mdb"

'Display frmLofin form

End Sub

Public Sub cetre(myForm As Form)

'Place form in center of screen
myForm.Left = (Screen.Width - myForm.Width) / 2
myForm.Top = (Screen.Height - myForm.Height) / 2

End Sub

Select frmLogin form in project view and click right mouse button. Select View code from drop down list. Add the following code to the login form:

Private try As Integer

Option Explicit

Private Sub cmdLogin_Click()

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sql As String

sql = "select * from passwords
where target='this' and login='" & txtLogin.Text & "' and password='" & txtPassword.Text & "'"
'MsgBox sql
rs.Open sql, Conn, adOpenKeyset, adLockPessimistic

If rs.BOF And rs.EOF Then
'If record is not found message displays
MsgBox "Incorrect login or password! Please try again.", vbOKOnly, "Password Keeper"
'count number of tries
try = try + 1
'Allows only 3 tries, then application stops
If try >= 3 Then
End If

Exit Sub


'If password correct, Main form is loaded and Login form is unloaded
Unload frmLogin

End If

End Sub

Private Sub Form_Load()

'initialize try variable when login form is loaded

try = 0

End Sub

Private Sub Form_Activate()

'Place form in center of the screen
cetre Me

End Sub

To Doanload the last version of VB Application source files

>>Part 2>>

Start Visual Basic: Part I

My eBooks on


No comments yet.

Add Comment

* Required information
(never displayed)
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
What is the fifth month of the year?
Enter answer:
Enter code:
Notify me of new comments via email.
Remember my form inputs on this computer.
I have read and understand the privacy policy. *
I have read and agree to the terms and conditions. *
Powered by Commentics