943,884 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Feb 27th, 2008
0

error updating access database using vb..

Expand Post »
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???
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vikas1111 is offline Offline
5 posts
since Feb 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

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.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Feb 27th, 2008
0

Re: error updating access database using vb..

Hi Shouvik..
Thanks .. I tried your code but i am getting the error msg "error in creating the new record."
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vikas1111 is offline Offline
5 posts
since Feb 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

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..
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
werks is offline Offline
57 posts
since Jan 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

Click to Expand / Collapse  Quote originally posted by vikas1111 ...
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?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
werks is offline Offline
57 posts
since Jan 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

Try removing the error handler to detect which line the error occur
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
werks is offline Offline
57 posts
since Jan 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vikas1111 is offline Offline
5 posts
since Feb 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

"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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vikas1111 is offline Offline
5 posts
since Feb 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

Do you have a field name text1 in your table in the database?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
werks is offline Offline
57 posts
since Jan 2008
Feb 27th, 2008
0

Re: error updating access database using vb..

Click to Expand / Collapse  Quote originally posted by vikas1111 ...
Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text
BTW what kind of error?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
werks is offline Offline
57 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to: Update record
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: update number of functions being called





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC