News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Creating VB database applications using ADO control - Code

Started by VelMurugan, Jul 18, 2008, 07:46 PM

Previous topic - Next topic

VelMurugan

Creating VB database applications using ADO control

Now, you need to write code for all the command buttons. After which, you can make the ADO control invisible.

For the Save button, the program codes are as follow:

Private Sub cmdSave_Click()
adoBooks.Recordset.Fields("Title") = txtTitle.Text
adoBooks.Recordset.Fields("Year Published") = txtPub.Text
adoBooks.Recordset.Fields("ISBN") = txtISBN.Text
adoBooks.Recordset.Fields("PubID") = txtPubID.Text
adoBooks.Recordset.Fields("Subject") = txtSubject.Text
adoBooks.Recordset.Update
End Sub


For the Add button, the program codes are as follow:

Private Sub cmdAdd_Click()
adoBooks.Recordset.AddNew
End Sub


For the Delete button, the program codes are as follow:

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

 

For the Cancel button, the program codes are as follow:

Private Sub cmdCancel_Click()
txtTitle.Text = ""
txtPub.Text = ""
txtPubID.Text = ""
txtISBN.Text = ""
txtSubject.Text = ""
End Sub


For the Previous (<) button, the program codes are

Private Sub cmdPrev_Click()
If Not adoBooks.Recordset.BOF Then
adoBooks.Recordset.MovePrevious
If adoBooks.Recordset.BOF Then
adoBooks.Recordset.MoveNext
End If
End If
End Sub


For the Next(>) button, the program codes are

Private Sub cmdNext_Click()
If Not adoBooks.Recordset.EOF Then
adoBooks.Recordset.MoveNext
If adoBooks.Recordset.EOF Then
adoBooks.Recordset.MovePrevious
End If
End If
End Sub