Lesson 29: Creating Advanced VB database application using ADO control

<Previous Lesson> <<Home>>< Next Lesson>

In previous lessons, you have learned how to design database applications using data control and ADO control. However, those applications are very simple and plain . In this lesson, you will learn how to create a more advanced database application using ADO control. The application you are going to create is known as an electronic library. This electronic library will be able to accept the user registration as well as handling login command that require the user's  password, thus enhancing the security aspect of the database. Basically, the application will constitute a welcome menu, a registration menu, a Login menu and the main database menu. The sequence of the menus is illustrated in Figure 29.1 follow:

Figure 29.1

29.1 The Welcome Menu

First of all, you need to design the Welcome menu. You can follow the example as shown in Figure 29.1 below:

Figure 29.2: The Welcome Menu

In this form, you need to insert three command buttons and set their properties as shown in Table 29.1 below:

Table 29.1

Propery Name Setting
Form name main_menu
command button 1  Name cmdRegister
command button 1 Caption Register
command button 2 Name cmdLogin
command button 2 Caption Login
command button 3 Name cmdCancel
command button 3 Caption Cancel

The code

Private Sub cmdLogin_Click()


End Sub

Private Sub cmdRegister_Click()


End Sub

29.2 The Registration Form

If a new user click the Register button, the registration form will appear as illustrated in Figure 29.3 below:

Figure 29.3: The Registration Form

This registration forms consist of two text boxes , three command buttons and an ADO control. Their properties are set as in Table 29.2 below:


Table 29.2

Propery Name Setting
Form name Register
textbox 1 name txtName
textbox 2 name txtpassword
textbox 2 PasswordChar *
command button 1 name cmdConfirm
command button 1 Caption Confirm
command button 2 name cmdClear
command button 2 Caption Clear
command button 3 name cmdCancel
command button 3 Caption Cancel
ADO control name UserInfo

Note that the PasswordChar of textbox 2 is set as * which means users will not be able to see the actual characters they enter, they will only see the * symbol.

The code

Private Sub cancel_Click( )
End Sub

Private Sub cmdClear_Click( )
txtName.Text = ""
txtpassword.Text = ""

End Sub

Private Sub cmdConfirm_Click()

UserInfo.Recordset.Fields("username") = txtName.Text
UserInfo.Recordset.Fields("password") = txtpassword.Text



End Sub

Private Sub Form_Load()
End Sub


29.3 The Login Menu

The Login menu is illustrated as follow:

Figure 29.4: The Login Menu

There are two text boxes and a command button,  their properties are set as in Table 29.3 below:

Table 29.3

Propery Name Setting
Textbox 1 name txtName
Textbox 2 name txtpassword
Command button 1 name cmdLogin
Command button 1 Caption Login
Form name Login_form

The code

Private Sub cmdLogin_Click()

Dim usrname As String
Dim psword As String
Dim usernam As String
Dim pssword As String
Dim Msg As String

usrname = txtName.Text
psword = txtpassword.Text

Do Until Register.UserInfo.Recordset.EOF
If Register.UserInfo.Recordset.Fields("username").Value = usrname And Register.UserInfo.Recordset.Fields("password").Value = psword Then
Exit Sub

End If


Msg = MsgBox("Invalid password, try again!", vbOKCancel)
If (Msg = 1) Then
txtName.Text = ""
txtpassword = ""

End If

End Sub

29.4 The Main Database Manager

The main database manager is illustrated in Figure 29.5 below:

Figure 29.5

The properties of all controls are listed in Table 29.4 below:


Table 29.4

Propert Name Setting
Form name frmLibrary
ADO control name adoLibrary
ADO visible False
TextBox 1 name txtTitleA
TextBox 2 name txtAuthor
TextBox 3name txtPublisher
TextBox 4 name txtYear
TextBox 5 name txtCategory
Command button 1 name cmdSave
Command button 1 caption &Save
Command button 2 name cmdNew
Command button 2 caption &New
Command button 3 name cmdDelete
Command button 3 caption &Delete
Command button 4 name cmdCancel
Command button 4 caption &Cancel
Command button 5 name cmdNext
Command button 5 caption N&ext
Command button 6 name cmdPrevious
Command button 6 caption &Previous
Command button 7 name cmdExit
Command button 7 caption E&xit

The code

Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtAuthor.Text = ""
txtPublisher.Text = ""
txtYear.Text = ""
txtCategory.Text = ""
End Sub

Private Sub cmdDelete_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Deletion Confirmation")
If Confirm = vbYes Then
MsgBox "Record Deleted!", , "Message"
MsgBox "Record Not Deleted!", , "Message"
End If

End Sub

Private Sub cmdExit_Click()
End Sub

Private Sub cmdNew_Click()

End Sub

Private Sub cmdNext_Click()
If Not adoLibrary.Recordset.EOF Then
If adoLibrary.Recordset.EOF Then
End If
End If
End Sub

Private Sub cmdPrevious_Click()
If Not adoLibrary.Recordset.BOF Then
If adoLibrary.Recordset.BOF Then
End If
End If
End Sub

Private Sub cmdSave_Click()

adoLibrary.Recordset.Fields("Title").Value = txtTitle.Text
adoLibrary.Recordset.Fields("Author").Value = txtAuthor.Text

End Sub

  Bookmark and Share

<Previous Lesson> <<Home>>< Next Lesson>

Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved |Contact: admin@vbtutor.net

[Privacy Policy]