Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to modify data? I have

Status
Not open for further replies.

kalpsv

Programmer
Jun 12, 2002
58
IN
how to modify data?




I have started a project in vb6 and access as the database.
when I go for modifying it displays an error message that the updation will create duplicate index or key. My primary key is branch_code_no, txn_dt and sl_no.

I am using the following code in slno private sub

Private Sub txtsl_KeyPress(KeyAscii As Integer)
Dim rs2 As Recordset
Dim l_brcode, l_slno As Integer
l_brcode = Val(txtbrcd)
l_slno = Val(txtsl)

Set rs2 = db.OpenRecordset("select max(serial_no) from ppftxn where brcd = " & txtbrcd)
If KeyAscii = 13 Or KeyAscii = 9 Then
rs.FindFirst "brcd = " & l_brcode

If rs.NoMatch = False And (rs(0) = l_brcode And rs(2) = l_slno) Then
If Val(txtsl) = rs(2) Then
MsgBox ("This Serial No. is already there for this Branch")
txtsl.Locked = False
txtsl.Enabled = True
txtsl.SetFocus
txtsl.Text = ""
Exit Sub

End If
If LBLMODE = "MODIFY" Then
txtsub.SetFocus
End If
Else
txtsub.Enabled = True
txtsub.SetFocus
End If
rs2.MoveFirst
If Val(txtsl) < 1 Or Val(txtsl) > 9999 Or IsNumeric(txtsl) = False Then
MsgBox (&quot;Serial No. should between 0001 and 9999&quot;)

txtsl.SetFocus
ElseIf IsNull(rs2.Fields(0)) Then
If txtsl <> 1 Then
MsgBox &quot;Error Serial Number missing&quot;
flag_vouch = 1
End If
txtsub.Locked = False
txtsub.Enabled = True
txtsub.SetFocus
ElseIf rs2.Fields(0) = txtsl Then
MsgBox &quot;This serial already entered for this branch!!&quot;
flag_vouch = 1
txtsl.Locked = False
txtsl.Enabled = True
txtsl.Text = &quot;&quot;
txtsl.SetFocus

ElseIf rs2.Fields(0) + 1 <> txtsl Then
MsgBox &quot;Error Serial Number missing&quot;
flag_vouch = 2
txtsub.Locked = False
txtsub.Enabled = True
txtsub.SetFocus
Else
txtsub.Locked = False
txtsub.Enabled = True
txtsub.SetFocus
End If
End If
End Sub

Can you help me.
bye
 
Hi,
When you say you want to modify data, I believe you refer to editing the record pointed out by the primary keys. The thing is you normally don't try to change the primary key once it is saved.

So tell us what exactly you are trying to do when you get that error message?

Hope it helps. Let me know what happens. With regards,
PGK
 
to dgk
even if i alter the other fields (not the primary key) it gives the sameerror
kindly help me
 
Hi,
Give us the error message that you get. It will help us. Hope it helps. Let me know what happens.
With regards,
PGK
 
How are you generating (or specifying) your primary key? Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top