DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   error updating access database using vb.. (http://www.daniweb.com/forums/thread111111.html)

vikas1111 Feb 27th, 2008 4:16 am
error updating access database using vb..
 
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???

choudhuryshouvi Feb 27th, 2008 5:18 am
Re: error updating access database using vb..
 
there will be a little bit modification on your code and everything will be ok.

try this :-
Dim addnew As Boolean

addnew=true

on error goto err1

If text1.Text = "" Then
  MsgBox " enter the company name"
  text1.SetFocus
  exit sub
end if

If text2.Text = "" Then
  MsgBox " enter the company address"
  text2.SetFocus
  exit sub
end if

rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
rsnew3.addnew
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text
rsnew3.Update

if addnew=true then MsgBox " add new successful ", vbInformation, "successful"

if rsnew3.state=adstateopen then rsnew3.close
set rsnew3=nothing

exit sub

err1:
    err.clear
    addnew=false
    msgbox "error in creating the new record."
    set rsnew3=nothing
    exit sub
End Sub

get back with your result.

regards
Shouvik

vikas1111 Feb 27th, 2008 5:43 am
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."

werks Feb 27th, 2008 7:46 am
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..

werks Feb 27th, 2008 7:48 am
Re: error updating access database using vb..
 
Quote:

Originally Posted by vikas1111 (Post 546659)
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?

werks Feb 27th, 2008 7:50 am
Re: error updating access database using vb..
 
Try removing the error handler to detect which line the error occur

vikas1111 Feb 27th, 2008 7:57 am
Re: error updating access database using vb..
 
Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text

vikas1111 Feb 27th, 2008 7:59 am
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....

werks Feb 27th, 2008 8:06 am
Re: error updating access database using vb..
 
Do you have a field name text1 in your table in the database?

werks Feb 27th, 2008 8:07 am
Re: error updating access database using vb..
 
Quote:

Originally Posted by vikas1111 (Post 546739)
Hi Kenneth...
I am getting error in these lines..
rsnew3!text1 = text1.Text
rsnew3!text2 = text2.Text

BTW what kind of error?


All times are GMT -4. The time now is 4:25 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC