PDA

View Full Version : please why dont update



malkasoft10
08-12-2006, 03:59 AM
hi every body

i have problem when i try update exist data the massege runtime error
3022 appear Duplicate value in index, primary key

i used DAO and this is the code
Private Sub Command26_Click()
Dim rs As DAO.Recordset
Dim strSourceTable As String
Set LAMA = CurrentDb
Set rs = LAMA.OpenRecordset("patient", dbOpenDynaset)
'If rs.BOF = False Then
rs.Edit
rs!pid = [Forms]![P1]![pid]
rs!pname = [Forms]![P1]![pname]
rs!gender = [Forms]![P1]![gender]
rs!age = [Forms]![P1]![age]
rs!tel = [Forms]![P1]![tel]
rs!address = [Forms]![P1]![address]
rs!remark = [Forms]![P1]![remark]
rs.update

rs.Close
pid = Null
pname = Null
gender = Null
age = Null
tel = Null
address = Null
remark = Null
'Me.pid.Locked = True
Me.pname.Locked = True
Me.age.Locked = True
Me.tel.Locked = True
Me.address.Locked = True
Me.remark.Locked = True
Me.gender.Locked = True
Set LAMA = Nothing
End Sub

stanl
08-12-2006, 05:18 AM
your code is a little confusing. Is there only 1 record in the patients dynaset? Because what is happening is you are opening a dynaset and editing the first record. Based on the error, I assume you are setting a field to a duplicate primary key that exists in another record in the dynaset.

My only suggestion is build your dynaset based on a SELECT query of the underlying table that returns only the single patient record you are interested in.

.02
Stan

asingh
08-12-2006, 08:01 AM
Do you have a primary key set on the table...the table you are trying to Update [edit].....?

malkasoft10
08-12-2006, 10:38 PM
yes in fact there is primery key as id but when i delete the primery key and try to update all record will update in same date and also new record will add i will attach my project to help me. ANY BODY CAN HELPE ME TO UPDATE RECORD BY USEING SELECT >

THANKS FOR YOUR INTREAST

asingh
08-13-2006, 08:36 AM
Hi Malkasoft10,

Please attach a zipped version [remove confidential data if you want] of the .MDB Access file. Lets have a look at it....and try to get the updata method to work...?


regards,
asingh

malkasoft10
08-13-2006, 11:26 PM
dear friend

i was attached the sub of my project you can see the problem

Imdabaum
08-14-2006, 09:51 AM
Private Sub Command26_Click()
Dim rs As DAO.Recordset
Dim strSourceTable As String
Set LAMA = CurrentDb
Set rs = LAMA.OpenRecordset("patient", dbOpenDynaset)
'--------->>>>>>>>>>>>> rs.FindFirst ("[id] = " & [Forms]![In]![id]) <<<<<<<<<<<<<<<<<<<<<<------------------
rs.Edit
rs!pid = [Forms]![P1]![pid
rs!pname = [Forms]![P1]![pname]
rs!gender = [Forms]![P1]![gender]
rs!age = [Forms]![P1]![age]
rs!tel = [Forms]![P1]![tel]
rs!address = [Forms]![P1]![address]
rs!remark = [Forms]![P1]![remark]
rs.update

rs.Close
pid = Null
pname = Null
gender = Null
age = Null
tel = Null
address = Null
remark = Null
'Me.pid.Locked = True
Me.pname.Locked = True
Me.age.Locked = True
Me.tel.Locked = True
Me.address.Locked = True
Me.remark.Locked = True
Me.gender.Locked = True
Set LAMA = Nothing
End Sub

Hope that helps.

Just out of curiosity do you need this Dim strSourceTable As String in the declarations at top? You don't use it in this code, if it is part of code you removed for privacy disregard this comment.