rs!dealercode = Text1.Text
rs!dealername = Text2.Text
rs!dealeraddress = Text3.Text
rs!pincode = Text4.Text
rs!city = Text5.Text
rs!State = Text6.Text
rs!email = Text7.Text
rs!phone = Text8.Text
rs.update

this is my update code

Maybe you could post the error message that you are getting for us to help you, since we can't find any mistake in the that you've given.

duplication is occur when i update a record.with these code. it replace the first record
and

Post your sql statement here before you add the record..

I do not see a rs.AddNew line there. Post the entire subs code please.

Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\item.mdb"
cn.Open
SQL = "select * from t1"

rs.CursorLocation = adUseClient
rs.Open , cn, adOpenDynamic, adLockOptimistic`

End Sub
with these code i getting an error "commnd text was not set for the object"
error focus on this statement ''''''' rs.Open , cn, adOpenDynamic, adLockOptimistic'''''

That is because you never assoceated the seelct statement stored in SQL the variable to the rs.open method.

try this

rs.Open SQL, cn, adOpenDynamic, adLockOptimistic

Code as follow...

Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

Dim strSql As String

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\item.mdb"
cn.Open

strSql = "SELECT * FROM t1"

rs.CursorLocation = adUseClient
rs.Open strSql , cn, adOpenDynamic, adLockOptimistic

End Sub

The code is for a normal connection open. When you want to add a record...

Private Sub Comman1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

Dim strSql As String

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\item.mdb"
cn.Open

strSql = "SELECT * FROM t1"

rs.CursorLocation = adUseClient
rs.Open strSql , cn, adOpenDynamic, adLockOptimistic

rs.AddNew     
rs!dealercode = Text1.Text
rs!dealername = Text2.Text
rs!dealeraddress = Text3.Text
rs!pincode = Text4.Text
rs!city = Text5.Text
rs!State = Text6.Text
rs!email = Text7.Text
rs!phone = Text8.Text
rs.Update
This article has been dead for over six months. Start a new discussion instead.