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 ("Serial No. should between 0001 and 9999"
txtsl.SetFocus
ElseIf IsNull(rs2.Fields(0)) Then
If txtsl <> 1 Then
MsgBox "Error Serial Number missing"
flag_vouch = 1
End If
txtsub.Locked = False
txtsub.Enabled = True
txtsub.SetFocus
ElseIf rs2.Fields(0) = txtsl Then
MsgBox "This serial already entered for this branch!!"
flag_vouch = 1
txtsl.Locked = False
txtsl.Enabled = True
txtsl.Text = ""
txtsl.SetFocus
ElseIf rs2.Fields(0) + 1 <> txtsl Then
MsgBox "Error Serial Number missing"
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
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 ("Serial No. should between 0001 and 9999"
txtsl.SetFocus
ElseIf IsNull(rs2.Fields(0)) Then
If txtsl <> 1 Then
MsgBox "Error Serial Number missing"
flag_vouch = 1
End If
txtsub.Locked = False
txtsub.Enabled = True
txtsub.SetFocus
ElseIf rs2.Fields(0) = txtsl Then
MsgBox "This serial already entered for this branch!!"
flag_vouch = 1
txtsl.Locked = False
txtsl.Enabled = True
txtsl.Text = ""
txtsl.SetFocus
ElseIf rs2.Fields(0) + 1 <> txtsl Then
MsgBox "Error Serial Number missing"
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