Primary key error msg
-
hello all, am a begginer in vb. am creating one small project using vb6.0 and msacess 2003. my problem is i have set one field as a Primary key in that if the no entered is alredy there in databse it was return some error msg, but in my project instead of that error msg i want to create some msgbox that told the no u typed is already there pease choose another. please give me any syntax for that coding? below code is return by me in the insert click. Please give me suggesstion it is very urgent.
Private Sub cmdverify_Click() If (Text1.Text = "") Then MsgBox ("Please Scan Properly") Else rs.Open "select * from barcode", con, adOpenDynamic, adLockOptimistic rs.AddNew rs!barcode = Text1.Text rs.Update Text1.Text = "" Text1.SetFocus rs.Close End If End Sub
-
hello all, am a begginer in vb. am creating one small project using vb6.0 and msacess 2003. my problem is i have set one field as a Primary key in that if the no entered is alredy there in databse it was return some error msg, but in my project instead of that error msg i want to create some msgbox that told the no u typed is already there pease choose another. please give me any syntax for that coding? below code is return by me in the insert click. Please give me suggesstion it is very urgent.
Private Sub cmdverify_Click() If (Text1.Text = "") Then MsgBox ("Please Scan Properly") Else rs.Open "select * from barcode", con, adOpenDynamic, adLockOptimistic rs.AddNew rs!barcode = Text1.Text rs.Update Text1.Text = "" Text1.SetFocus rs.Close End If End Sub
try this: rs.Open "Select * from barcode Where barcodeid='" & txtbarcodeid.Text & "',con,1,3 if rs.eof then rs.addnew rs.fields("barcode")=text1.text rs.Update else // if existed msgbox "Record Existed" endif NOTE: make sure you have a "WHERE" to your SELECT so that you have a unique record to search.
Don't block the drive way of all the newbies in programming. :)
-
try this: rs.Open "Select * from barcode Where barcodeid='" & txtbarcodeid.Text & "',con,1,3 if rs.eof then rs.addnew rs.fields("barcode")=text1.text rs.Update else // if existed msgbox "Record Existed" endif NOTE: make sure you have a "WHERE" to your SELECT so that you have a unique record to search.
Don't block the drive way of all the newbies in programming. :)