Hi,
I'm working on a relatively old database that others created, and in order to deal with a duplicates issue I created a work-around by deleting all but one row on a specific problem table, tblRegisterCreation.
In the code in my workaround, I want to write an IF statement that counts the number of rows in tblRegisterCreation, and if there is more than one row then delete all but one.
To do this I created a numeric variable and tried to pass the value in to the .Execute command.
I am trying either:
Or
At first I tried including "numRows" inside the quotations. I appreciate any feedback.
I'm working on a relatively old database that others created, and in order to deal with a duplicates issue I created a work-around by deleting all but one row on a specific problem table, tblRegisterCreation.
In the code in my workaround, I want to write an IF statement that counts the number of rows in tblRegisterCreation, and if there is more than one row then delete all but one.
To do this I created a numeric variable and tried to pass the value in to the .Execute command.
I am trying either:
Code:
Dim strSQL As String
Dim numRows As long
strSQL = "DELETE * " _
& "FROM tblRegisterCreation " _
& "WHERE " & numRows & " > 1 IN" _
& "(SELECT TOP (numRows -1) tblRegisterCreation " _
& "FROM tblRegisterCreation "
If DCount("*", "tblRegisterCreation") > 1 Then
numRows = DCount("*", "tblRegisterCreation")
CurrentDb.Execute strSQL
End If
Or
Code:
Dim numRows As long
If DCount("*", "tblRegisterCreation") > 1 Then
numRows = DCount("*", "tblRegisterCreation")
CurrentDb.Execute "DELETE * " _
& "FROM tblRegisterCreation " _
& "WHERE " & numRows & " > 1 IN" _
& "(SELECT TOP (numRows -1) tblRegisterCreation " _
& "FROM tblRegisterCreation);"
End If
At first I tried including "numRows" inside the quotations. I appreciate any feedback.