I'm trying to use this code to check for duplicates with date and the value.
The code doesnt give me any error. But still it does give me the message duplicates found even though there are no duplicates in the database.
What am I doing wrong in here?
Code: Select all
Private Sub btnDuplicate_Click() Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim strSQL As String Dim bFound As Boolean Application.ScreenUpdating = False Application.EnableEvents = False Set cnn = New ADODB.Connection cnn.Open "Provider=Microsoft.ace.OLEDB.12.0; " & _ "Data Source=\\Files\Database.accdb;" Set rst = New ADODB.Recordset strSQL = "SELECT [ID ],[InfDate] FROM tbl WHERE [ID]=" & Me.ID.Value & " AND #" & Me.InfDate.Value & "#" rst.Open Source:=strSQL, ActiveConnection:=cnn, Options:=adCmdText bFound = Not rst.EOF rst.Close If bFound Then MsgBox "duplicates found. Please enter a new value!", vbExclamation, Me.ID.Value = "" Me.InfDate.Value = "" Exit Sub End If Me.TextBox1.Value = "" & Me.TExtBox2.Value & ". " Thankyou. rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing Application.EnableEvents = True Application.ScreenUpdating = True End Sub