error updating access database using vb..

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 5
Reputation: vikas1111 is an unknown quantity at this point 
Solved Threads: 0
vikas1111 vikas1111 is offline Offline
Newbie Poster

error updating access database using vb..

 
0
  #1
Feb 27th, 2008
Hi All..
I am trying to access records and edit and save the changes .. Here is the code



Private Sub cmd_edit_Click()
Dim addnew As Boolean
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
rsnew3.addnew
If text1.Text = "" Then
MsgBox " enter the company name"
text1.SetFocus
rsnew3.Fields("text1").Value = text1.Text
End If
If text2.Text = "" Then
MsgBox " enter the company address"
text2.SetFocus
rsnew3.Fields("text2").Value = text2.Text
End If
rsnew3.Update
rsnew3.Close
MsgBox " add new successful ", vbInformation, "successful"
End Sub


Private Sub Form_Load()
Dim cs As String
c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
rsnew2.Open "select * from company", c, adOpenDynamic
Me.text1.Text = rsnew2(2)
Me.text2.Text = rsnew2(3)

End Sub


I am getting message that "add new successful" but records are not actually updated...
What should i do ..? can any1 help me pls???
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: error updating access database using vb..

 
0
  #2
Feb 27th, 2008
there will be a little bit modification on your code and everything will be ok.

try this :-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim addnew As Boolean
  2.  
  3. addnew=true
  4.  
  5. on error goto err1
  6.  
  7. If text1.Text = "" Then
  8. MsgBox " enter the company name"
  9. text1.SetFocus
  10. exit sub
  11. end if
  12.  
  13. If text2.Text = "" Then
  14. MsgBox " enter the company address"
  15. text2.SetFocus
  16. exit sub
  17. end if
  18.  
  19. rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
  20. rsnew3.addnew
  21. rsnew3!text1 = text1.Text
  22. rsnew3!text2 = text2.Text
  23. rsnew3.Update
  24.  
  25. if addnew=true then MsgBox " add new successful ", vbInformation, "successful"
  26.  
  27. if rsnew3.state=adstateopen then rsnew3.close
  28. set rsnew3=nothing
  29.  
  30. exit sub
  31.  
  32. err1:
  33. err.clear
  34. addnew=false
  35. msgbox "error in creating the new record."
  36. set rsnew3=nothing
  37. exit sub
  38. End Sub

get back with your result.

regards
Shouvik
Last edited by choudhuryshouvi; Feb 27th, 2008 at 5:18 am.
Shouvik_The_Expert_Coder
Have a problem? Don't worry just give me a call and I'll fix it for you.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 5
Reputation: vikas1111 is an unknown quantity at this point 
Solved Threads: 0
vikas1111 vikas1111 is offline Offline
Newbie Poster

Re: error updating access database using vb..

 
0
  #3
Feb 27th, 2008
Hi Shouvik..
Thanks .. I tried your code but i am getting the error msg "error in creating the new record."
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: werks is an unknown quantity at this point 
Solved Threads: 1
werks's Avatar
werks werks is offline Offline
Junior Poster in Training

Re: error updating access database using vb..

 
0
  #4
Feb 27th, 2008
I get the problem if save the record with NULL value then it will save Empty String and if you save the record with a value it will not save any record because you don't specify the code to save the record..
Kenneth
"Better Than Yesterday"
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: werks is an unknown quantity at this point 
Solved Threads: 1
werks's Avatar
werks werks is offline Offline
Junior Poster in Training

Re: error updating access database using vb..

 
0
  #5
Feb 27th, 2008
Originally Posted by vikas1111 View Post
Hi Shouvik..
Thanks .. I tried your code but i am getting the error msg "error in creating the new record."
In what line of code you get the error?
Kenneth
"Better Than Yesterday"
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: werks is an unknown quantity at this point 
Solved Threads: 1
werks's Avatar
werks werks is offline Offline
Junior Poster in Training

Re: error updating access database using vb..

 
0
  #6
Feb 27th, 2008
Try removing the error handler to detect which line the error occur
Kenneth
"Better Than Yesterday"
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 5
Reputation: vikas1111 is an unknown quantity at this point 
Solved Threads: 0
vikas1111 vikas1111 is offline Offline
Newbie Poster

Re: error updating access database using vb..

 
0
  #7
Feb 27th, 2008
Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 5
Reputation: vikas1111 is an unknown quantity at this point 
Solved Threads: 0
vikas1111 vikas1111 is offline Offline
Newbie Poster

Re: error updating access database using vb..

 
0
  #8
Feb 27th, 2008
"I get the problem if save the record with NULL value then it will save Empty String and if you save the record with a value it will not save any record because you don't specify the code to save the record.. " You are right....
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: werks is an unknown quantity at this point 
Solved Threads: 1
werks's Avatar
werks werks is offline Offline
Junior Poster in Training

Re: error updating access database using vb..

 
0
  #9
Feb 27th, 2008
Do you have a field name text1 in your table in the database?
Kenneth
"Better Than Yesterday"
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: werks is an unknown quantity at this point 
Solved Threads: 1
werks's Avatar
werks werks is offline Offline
Junior Poster in Training

Re: error updating access database using vb..

 
0
  #10
Feb 27th, 2008
Originally Posted by vikas1111 View Post
Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text
BTW what kind of error?
Kenneth
"Better Than Yesterday"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC