Loading

Codes Not working

3 posts / 0 new
Last post
Offline
Joined: 07/10/2010
Codes Not working

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
admin's picture
Offline
Joined: 11/14/2008
re: Codes Not working

The problem is very obvious. You did not add error trapping or form validation.

In the cmdSave_Click procedure you could add a code below to validate a form:

  1. If txtNo.Text = "" Then
  2. Msgbox "Please enter a Number."
  3.  
  4. Exit Sub
  5. End If
  6.  
  7. If txtName.Text = "" Then
  8. Msgbox "Please enter Name."
  9.  
  10. Exit Sub
  11. End If

etc...

You may try adding error handling also:

On Error GoTo err_Handling

err_Handling:
Msgbox err.description

mrhumble's picture
Offline
Joined: 04/02/2010
sir Admin

Hello Sir

pano po ba ebackup ang sql server 2005 thru vb6
hope your answer!!!
more power

mrhumble

http://codes-47.blogspot.com

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.