There are several ways but I find the easiest is just to attempt the insert and then note the return values to see if it succeeded.
Code:
SQL = "INSERT INTO myTable (fld1, fld2, fld3) " & _
"VALUES ('a', 2, 'x') "
db.Execute SQL
If db.RecordsAffected = 0 Then
[COLOR=black cyan]' Duplicate Record Message[/color]
End If
dim mydb as Database
dim rst as recordset
set mydb = currentdb
set rst mydb.openrecordset("select count(*) from mytable where myfield =" & myvar & " myfield2 =" & myvar2... )
if not (rst.bof and rst.eof) then
msgbox "record exist"
end if
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.