0 Replies - 269 Views - Last Post: 27 January 2012 - 06:17 PM Rate Topic: -----

Topic Sponsor:

#1 Fredex  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 16-January 12

List view VS. Data Grid!

Posted 27 January 2012 - 06:17 PM

who know what is the code or SQL Statement on how to add, edit, delete and search record from MSAccess using List View instead of Datagrid? Please share your idea and knowledge to help others. I want to learn how to use listview because it is the most popular nowadays as compare to datagrid so please share your knowledge..thanks very much..

Here is my sample code of add, edit, delete and search record from MSAccess using datagrid:
Private Sub cmdAdd_Click()
If txtName = "" Or txtAge = "" Then
    MsgBox "Fill up all fields.", "Requirement"
ElseIf IsNumeric(txtAge) = False Then
    MsgBox "Invalid age.", "Requirement"
    txtAge = ""
    txtAge.SetFocus
Else
    adoEmployee.Recordset.AddNew
    With adoEmployee.Recordset
        .Fields(fldName) = txtName
        .Fields(fldAge) = txtAge
        .Fields(fldBirthDate) = dtpBDate.Value
        .Update
    End With
    txtName = ""
    txtAge = ""
    MsgBox "Record added", "Add"
End If
End Sub

Private Sub cmdDel_Click()
If MsgBox("Are you sure?", vbQuestion + vbYesNo, "Delete Confirmation") = vbYes Then
    adoEmployee.Recordset.Delete
    adoEmployee.Recordset.Requery
    adoEmployee.Refresh
End If

End Sub

Private Sub cmdEdit_Click()
If cmdEdit.Caption = "&Edit" Then
    txtName = adoEmployee.Recordset.Fields!fldName
    txtAge = adoEmployee.Recordset.Fields!fldAge
    dtpBDate.Value = adoEmployee.Recordset.Fields!fldBirthDate
    cmdEdit.Caption = "&Update"
Else
    adoEmployee.Recordset.Update
    With adoEmployee.Recordset
        .Fields!fldName = txtName
        .Fields!fldAge = txtAge
        .Fields!fldBirthDate = dtpBDate.Value
        .Update
    End With
    MsgBox "Record has been updated", "Edit"
    cmdEdit.Caption = "&Edit"
    adoEmployee.Refresh
End If
End Sub

Private Sub cmdSearch_Click()
adoEmployee.RecordSource = "Select * From tblEmployee when fldName Like " '" & txtSearch & "%" & "'"
adoEmployee.Refresh
End Sub




Is This A Good Question/Topic? 0
  • +

Page 1 of 1