C
Carvel
Guest
Hi All,
I am new to MS Access VBA, but not to VBA or to MS Access.
Thanks in advance for whatever help you can give me.
I am trying to verify whether or not duplicate records exist in a table (General Flying & Ownership Expenses) using VBA. What is the best way to proceed? I designed a query that counts duplicate records (see below). A duplicate record would be two records having the same "Type" and the same "Year"
SELECT
[General Flying & Ownership Expenses].Year,
[General Flying & Ownership Expenses].Type,
Count([General Flying & Ownership Expenses].Type)
AS CountOfType
FROM [General Flying & Ownership Expenses]
GROUP BY
[General Flying & Ownership Expenses].Year,
[General Flying & Ownership Expenses].Type
HAVING
(((Count([General Flying & Ownership Expenses].Type))>1));
What I want is if the results of this query for CountOfType are greater than 1 (i.e. there are duplicates), a message box will pop up indicating the table where the error is coming from and for the Sub to halt (see pseudo-code below).
Pseudo-Code
Sub Duplicate_Tester
Duplicate Test Process
if (results from Duplicate Test Process) > 1 then
msgbox(“Duplicate records in General Flying and Ownership Expenses”)
End
end if
End Sub
How to do this? Should I be using a query at all? I tried using the MS Access help and found it baffling.
Thank you!
- Kevin
I am new to MS Access VBA, but not to VBA or to MS Access.
Thanks in advance for whatever help you can give me.
I am trying to verify whether or not duplicate records exist in a table (General Flying & Ownership Expenses) using VBA. What is the best way to proceed? I designed a query that counts duplicate records (see below). A duplicate record would be two records having the same "Type" and the same "Year"
SELECT
[General Flying & Ownership Expenses].Year,
[General Flying & Ownership Expenses].Type,
Count([General Flying & Ownership Expenses].Type)
AS CountOfType
FROM [General Flying & Ownership Expenses]
GROUP BY
[General Flying & Ownership Expenses].Year,
[General Flying & Ownership Expenses].Type
HAVING
(((Count([General Flying & Ownership Expenses].Type))>1));
What I want is if the results of this query for CountOfType are greater than 1 (i.e. there are duplicates), a message box will pop up indicating the table where the error is coming from and for the Sub to halt (see pseudo-code below).
Pseudo-Code
Sub Duplicate_Tester
Duplicate Test Process
if (results from Duplicate Test Process) > 1 then
msgbox(“Duplicate records in General Flying and Ownership Expenses”)
End
end if
End Sub
How to do this? Should I be using a query at all? I tried using the MS Access help and found it baffling.
Thank you!
- Kevin