By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

ADDITION TO RECORDSET<ERRORS

100+
P: 103
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2. txtid.Enabled = True
  3. If txtid.Text = " " Then
  4. MsgBox "Enter the id,Please!!!", vbOKOnly, "PAYROLL"
  5. txtid.SetFocus
  6. With txtid
  7. .SelStart = 0
  8. '.SelLength = Len(txtid.Text)
  9. .SetFocus
  10. End With
  11. Exit Sub
  12. ElseIf txtname.Text = " " Then
  13.  MsgBox "Enter the name,Please!!!", vbOKOnly, "PAYROLL"
  14.  'txtname.SetFocus
  15. Exit Sub
  16.  
  17.  With txtname
  18.    .SelStart = 0
  19. '  .SelLength = Len(txtname.Text)
  20.    .SetFocus
  21.  
  22. End With
  23.  'End If
  24. ElseIf txtwhr.Text = " " Then
  25. MsgBox "Enter  the working hours,Please!!!", vbOKOnly, "PAYROLL"
  26. txtwhr.SetFocus
  27. Exit Sub
  28. With txtwhr
  29.   .SelStart = 0
  30. '.SelLength = Len(txtwhr.Text)
  31.   .SetFocus
  32. End With
  33. ElseIf Form1.txtrate.Text = " " Then
  34. MsgBox "Enter  the rate,Please!!!", vbOKOnly, "PAYROLL"
  35. txtrate.SetFocus
  36. Exit Sub
  37. With txtrate
  38.   .SelStart = 0
  39.   .SetFocus
  40. End With
  41. ElseIf txtorate.Text = " " Then
  42. MsgBox "Enter the Overtime Rate,Please!!!", vbOKOnly, "PAYROLL"
  43. txtorate.SetFocus
  44.  Exit Sub
  45. With txtorate
  46.  .SelStart = 0
  47.   .SetFocus
  48.   End With
  49.   Else
  50. rs.Open "select * from empdetail Where ID='" & txtid.Text & "'", conn, adOpenStatic, adLockOptimistic
  51. If rs.EOF Then
  52. conn.Execute "insert into empdetail(id,name,whours,rate,otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
  53. MsgBox "INSERTED NEW RECORDS", vbOKOnly, "ADDING NEW RECORDS"
  54. Else
  55.  
  56. MsgBox "Duplicate Entry"
  57.   End If
  58.  
  59. rs.Close
  60. Set rs = Nothing
  61. ListView1.ListItems.Clear
  62. addcol
  63. Form1.txtid.Text = ""
  64. Form1.txtname.Text = ""
  65. Form1.txtwhr.Text = ""
  66. Form1.txtrate.Text = ""
  67. Form1.txtorate.Text = ""
  68. End If
  69.  
  70. End Sub
  71. Private Sub cmdBack_Click()
  72. Form1.txtid.Text = ""
  73. Form1.txtname.Text = ""
  74. Form1.txtwhr.Text = ""
  75. Form1.txtrate.Text = ""
  76. Form1.txtorate.Text = ""
  77. Form1.Hide
  78. MDIForm1.Show
  79. End Sub

This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
Please Go through...........!!!!!~
Where I HAve go wrong????
Jan 11 '08 #1
Share this Question
Share on Google+
3 Replies


Dököll
Expert 100+
P: 2,364
code:vb

This above code is for adding four fields to databse where id the primary kiey.Please go through because,its works for once,ie when one data gets inserted,u dont have any pblm.But whenthe computation is done for the second time without closing the window,an error occurs!!!
Please Go through...........!!!!!~
Where I HAve go wrong????
Hello, Vbbeginner07!

What are you hoping the above code does?

I am just trying to get a handle on what you are asking for. Can you go into it a little more?

Dököll
Jan 11 '08 #2

100+
P: 103
Hello, Vbbeginner07!
What are you hoping the above code does?
I am just trying to get a handle on what you are asking for. Can you go into it a little more?
Dököll
Hi DoKoll,
the above code is for ADD ing datas to a database,the form actually contains five fileds
id ,which is the primary key
name(of employee)
working hours(emp)
rate(per hours)
overtime rate(if he does,per hours)
The code works for the very first time,ie when one data gets inserted into the database,if we click ADD button(command button)it gives errors,where i have given specific constraints for each field,why is it so...???
Where i have gone wrong???
Ant More explanation???

Nick
Jan 11 '08 #3

debasisdas
Expert 5K+
P: 8,127
please try to use this

Expand|Select|Wrap|Line Numbers
  1. conn.BeginTrans
  2. conn.Execute "insert into empdetail(id,name,whours,rate,otrate) values ('" & txtid & "','" & txtname & "','" & txtwhr & "','" & txtrate & "','" & txtorate & "')"
  3. conn.commmittrans
  4.  
that might help you.
Jan 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.