VBI 65.PNG

Before using methods for handling database application, design form with text boxes, labels, and ADODC control. Set properties for ADODC control such as connection string record set fields etc. Now add four command on the form. Change caption of these for command button as Add New, Submit, Clear and Exit. Follow the following step for using these command button –

(1) Double click on the form and make the following declaration in general section.

Option Explicit
    Dim a, c As Integer
    Dim b, d As String
    Dim e, f, g, h As Variant

(2) Double click on the add new command button and enter the code as follows –

Private Sub Command1_Click()
    Adodc1.Recordset.AddNew
    Text1.SetFocus
End Sub

(3) Double click on the submit command button and enter the code in the following format –

Private Sub Command2_Click()
    a = Val(Text1.Text)
    b = Text2.Text
    c = Val(Text3.Text)
    d = Text4.Text
    e = Val(Text5.Text)
    f = Val(Text6.Text)
    g = Val(Text7.Text)
    h = Val(Text8.Text)
    With Adodc1.Recordset
        .AddNew
        !EmployeeCode = a
        !EmployeeName = b
        !Age = c
        !City = d
        !BasicSalary = e
        !HRA = f
        !DA = g
        !NetSalary = h
    End With
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
End Sub

(4) Double click on the clear command button and enter the code in the following format –

Private Sub Command3_Click()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
End Sub

(5) Double click on the exist command button and write code in the following format –

Private Sub Command4_Click()
    End
End Sub

(6) Enter the following code for Text5 control at the LostFocus event

Private Sub Text5_LostFocus()
    Text6.Text = Val(Text5.Text) * 0.1
    Text7.Text = Val(Text5.Text) * 125
    Text8.Text = Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text)
End Sub

(7) Run the project and click add button, submit button, clear button, exist button to display operation of the form. Construct the form with labels, text boxes, ADODE control and command buttons in the following format –

VBO 65.PNG

Advertisements