View Single Post
  #1  
Old April 21st, 2008, 11:07 AM posted to microsoft.public.access.forms
hikaru
external usenet poster
 
Posts: 17
Default inserting new record, duplication error

hi all,
I am trying to insert a new record to the table, but if the Contract_No
(primary Key) of the record i'm trying to insert was similar to another one
that is already in the table, I recieve an error msg.. how can I show a
msgbox "There was a contract with the same No., please choose another one!!"
when the same contract_no already exist,, and insert the new record if there
were no similar contract_no in table.. I hope I explained it well.. I need
your help, please.

thanks in advance.

here is my code:

Private Sub cmdNext_Click()
Dim contNo As String

contNo = UCase(Me.Contract_No)

DoCmd.RunSQL ("INSERT INTO Tbl_Contracts (Contract_No, EmpID) VALUES ('" &
contNo & "'," & Me.EmpID & ")")


End Sub