E
esn
I have a form set up for data entry with a subform linking child
records in a different table. In the case where a user closes the
form halfway through entering child records then reopens it to finish
adding the child records, I don't want to keep the duplicate master
record they create when they reenter the information in the controls
bound to the master table. So I made a simple find duplicates query,
added a "MaxofID" field, and joined it to a delete query that should
delete the second instance of the duplicate record. I was going to
run this query whenever the form is closed. Unfortunately, I get an
error message saying Access is unable to delete the records from the
specified table. Any ideas? The help topic that pops up seems way
off, since it only discusses the possibility that the database is
opened as read only and I can manually delete the records from the
table with no problems. Here are the queries:
Find Duplicates Query:
SELECT First([UPFU Mammal Visit Data].Site) AS [Site Field], First
([UPFU Mammal Visit Data].Day) AS [Day Field], First([UPFU Mammal
Visit Data].Visit) AS [Visit Field], First([UPFU Mammal Visit
Data].Date) AS [Date Field], First([UPFU Mammal Visit
Data].Start_time) AS [Start_time Field], First([UPFU Mammal Visit
Data].End_tIme) AS [End_tIme Field], Count([UPFU Mammal Visit
Data].Site) AS NumberOfDups, Max([UPFU Mammal Visit Data].ID) AS
MaxOfID
FROM [UPFU Mammal Visit Data]
GROUP BY [UPFU Mammal Visit Data].Site, [UPFU Mammal Visit Data].Day,
[UPFU Mammal Visit Data].Visit, [UPFU Mammal Visit Data].Date, [UPFU
Mammal Visit Data].Start_time, [UPFU Mammal Visit Data].End_tIme
HAVING (((Count([UPFU Mammal Visit Data].Site))>1) AND ((Count([UPFU
Mammal Visit Data].End_tIme))>1));
Delete Query:
DELETE [UPFU Mammal Visit Data].*, [UPFU Mammal Visit Data].ID
FROM [Find duplicates for UPFU Mammal Visit Data] INNER JOIN [UPFU
Mammal Visit Data] ON ([Find duplicates for UPFU Mammal Visit Data].
[Date Field] = [UPFU Mammal Visit Data].Date) AND ([Find duplicates
for UPFU Mammal Visit Data].[End_tIme Field] = [UPFU Mammal Visit
Data].End_tIme) AND ([Find duplicates for UPFU Mammal Visit Data].
[Start_time Field] = [UPFU Mammal Visit Data].Start_time) AND ([Find
duplicates for UPFU Mammal Visit Data].[Visit Field] = [UPFU Mammal
Visit Data].Visit) AND ([Find duplicates for UPFU Mammal Visit Data].
[Day Field] = [UPFU Mammal Visit Data].Day) AND ([Find duplicates for
UPFU Mammal Visit Data].[Site Field] = [UPFU Mammal Visit Data].Site)
WHERE ((([UPFU Mammal Visit Data].ID)=[Find duplicates for UPFU Mammal
Visit Data]![MaxOfID]));
Thanks in advance for any insight!
records in a different table. In the case where a user closes the
form halfway through entering child records then reopens it to finish
adding the child records, I don't want to keep the duplicate master
record they create when they reenter the information in the controls
bound to the master table. So I made a simple find duplicates query,
added a "MaxofID" field, and joined it to a delete query that should
delete the second instance of the duplicate record. I was going to
run this query whenever the form is closed. Unfortunately, I get an
error message saying Access is unable to delete the records from the
specified table. Any ideas? The help topic that pops up seems way
off, since it only discusses the possibility that the database is
opened as read only and I can manually delete the records from the
table with no problems. Here are the queries:
Find Duplicates Query:
SELECT First([UPFU Mammal Visit Data].Site) AS [Site Field], First
([UPFU Mammal Visit Data].Day) AS [Day Field], First([UPFU Mammal
Visit Data].Visit) AS [Visit Field], First([UPFU Mammal Visit
Data].Date) AS [Date Field], First([UPFU Mammal Visit
Data].Start_time) AS [Start_time Field], First([UPFU Mammal Visit
Data].End_tIme) AS [End_tIme Field], Count([UPFU Mammal Visit
Data].Site) AS NumberOfDups, Max([UPFU Mammal Visit Data].ID) AS
MaxOfID
FROM [UPFU Mammal Visit Data]
GROUP BY [UPFU Mammal Visit Data].Site, [UPFU Mammal Visit Data].Day,
[UPFU Mammal Visit Data].Visit, [UPFU Mammal Visit Data].Date, [UPFU
Mammal Visit Data].Start_time, [UPFU Mammal Visit Data].End_tIme
HAVING (((Count([UPFU Mammal Visit Data].Site))>1) AND ((Count([UPFU
Mammal Visit Data].End_tIme))>1));
Delete Query:
DELETE [UPFU Mammal Visit Data].*, [UPFU Mammal Visit Data].ID
FROM [Find duplicates for UPFU Mammal Visit Data] INNER JOIN [UPFU
Mammal Visit Data] ON ([Find duplicates for UPFU Mammal Visit Data].
[Date Field] = [UPFU Mammal Visit Data].Date) AND ([Find duplicates
for UPFU Mammal Visit Data].[End_tIme Field] = [UPFU Mammal Visit
Data].End_tIme) AND ([Find duplicates for UPFU Mammal Visit Data].
[Start_time Field] = [UPFU Mammal Visit Data].Start_time) AND ([Find
duplicates for UPFU Mammal Visit Data].[Visit Field] = [UPFU Mammal
Visit Data].Visit) AND ([Find duplicates for UPFU Mammal Visit Data].
[Day Field] = [UPFU Mammal Visit Data].Day) AND ([Find duplicates for
UPFU Mammal Visit Data].[Site Field] = [UPFU Mammal Visit Data].Site)
WHERE ((([UPFU Mammal Visit Data].ID)=[Find duplicates for UPFU Mammal
Visit Data]![MaxOfID]));
Thanks in advance for any insight!