Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Database Programming Made Easy

This tutorial will teach you step by step on how to connect and manipulate database. If you'd like to suggest a tutorial please write a comment at the bottom of this article.

Read more...

Hire Us to Do Your Work

Do you want a customized system? Do you want to setup your own website to do business? Then we are here to help you in your programming needs.

Read more...

Search

Codes Not working
2 replies [Last post]
User offline. Last seen 8 weeks 2 days ago. Offline
Joined: 07/10/2010


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
User offline. Last seen 16 min 57 sec ago. 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
User offline. Last seen 2 weeks 4 days ago. 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://codesourcerepublic1.blogspot.com
strike when the Iron is Hot

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Step by Step Java Tutorial

In this tutorial you will learn how to program with Java. It has a rich of information to be educated well with Java.

Read more...

Do You Have Question?

Do you have any question related to computer programming? Visit our forum and post new topic on the category you like. Be gentle when asking a question.

Ask now...

Point of Sale

Point of Sale is very useful especially for supermarkets or restaurants. I have included a barcode scanner in this program. Please check it out.

Read more...