Codes Not working

Submitted by Omondi on
When i click on ADD it changes to SAVE and disables other buttons DELETE UPDATE SEARCH.When i click on SAVE and if texboxes are empty it brings an error,when i click search and i want to cancel the search from the inputbox it brings another error i also want to add cancel button or refresh button.How can i make this project to run well. WHere did i go wrong Here are my codes
  1. Private Sub Form_Load()
  2. Dim str As String
  3. Me.Caption = ""
  4. Set adoconn = Nothing
  5. adoconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=person.mdb;Persist Security Info=False"
  6. str = "select * from pers"
  7. rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
  8. rs.MoveFirst
  9. txtNo.Text = rs(0)
  10. txtName.Text = rs(1)
  11. txtDistrict.Text = rs(2)
  12. txtDob.Text = rs(4)
  13. txtPhone.Text = rs(3)
  14. txtID.Text = rs(5)
  15.  
  16.   End Sub
  17.  
  18. Private Sub cmdSave_Click()
  19.  
  20. rs(0) = txtNo.Text
  21. rs(1) = txtName.Text
  22. rs(2) = txtDistrict.Text
  23. rs(4) = txtDob.Text
  24. rs(3) = txtPhone.Text
  25. rs(5) = txtID.Text
  26. rs.Update
  27. MsgBox "The record has been saved successfully.", , "ADD"
  28. cmdFirst.Enabled = True
  29. cmdLast.Enabled = True
  30. cmdNext.Enabled = True
  31. cmdPrevious.Enabled = True
  32. cmdDelete.Enabled = True
  33. cmdSearch.Enabled = True
  34. cmdUpdate.Enabled = True
  35. cmdSave.Visible = False
  36. cmdAdd.Visible = True
  37. End Sub
  38.  
  39. Private Sub cmdSearch_Click()
  40. Dim key As Integer, str As String
  41. key = InputBox("Enter the Persons No whose details you want to know: ")
  42. Set rs = Nothing
  43. str = "select * from pers where no=" & key
  44. rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
  45. txtNo.Text = rs(0)
  46. txtName.Text = rs(1)
  47. txtDistrict.Text = rs(2)
  48. txtDob.Text = rs(4)
  49. txtPhone.Text = rs(3)
  50. txtID.Text = rs(5)
  51. Set rs = Nothing
  52. str = "select * from pers where no="
  53. rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
  54. If txtNo Is Null Then MsgBox "Invalid entry .", vbCancel, "Note it..."
  55.  
  56. End Sub