I have a Macro that runs a number of queries in sequence which work on data from a monthly .csv report. This report lists donors who have used our website to make a donation during the last month. One query identifies those donors who already are on our database and links them to their existing Donor Number. But the one that I am having trouble with is the next one which identifies new donors. The query is built on 2 queries. The one identifies the first unused Donor Number in our Donors Table and the other selects those records from the .csv report which don't have an existing record in our Donors Table. The query appends the new donors' details (including the next Donor Number) to the Donors Table. My problem is that the query tries to give the same number to all of the new Donors listed in the monthly .csv report and because the Donor Number field is a Primary Key this is not permitted.
How can I get this query to go looking for the next unused Donor Number for each new donor? Is there any way that this can be done in my Macro? Or do I need to use Visual Basic - if so I will need help with the wording as I am not proficient in this area (I can cut & paste!!).
I use the design mode to create my queries but the SQL version of it is as follows -
INSERT INTO Donors ( [Donor Number], Title, [Christian Names], Surname, [Address 1], [Address 2], [Town/City], Postcode, [EMail Address], [Use Email?], [Gift Aid Declaration?], Code )
SELECT [First Unused Donor Number].MinOfNumber, [Select New Donors from Website Monthly Reports].Title, [Select New Donors from Website Monthly Reports].[Christian Names], [Select New Donors from Website Monthly Reports].Surname, [Select New Donors from Website Monthly Reports].[Address 1], [Select New Donors from Website Monthly Reports].[Address 2], [Select New Donors from Website Monthly Reports].[Town/City], [Select New Donors from Website Monthly Reports].Postcode, [Select New Donors from Website Monthly Reports].Email, [Select New Donors from Website Monthly Reports].[Use Email?], [Select New Donors from Website Monthly Reports].[Gift Aid Declaration?], IIf([Gift Aid Declaration?]="Yes","GJ","DJ") AS Exp1
FROM [First Unused Donor Number], [Select New Donors from Website Monthly Reports];
Any guidance would be much appreciated.