Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / September 2008

Tip: Looking for answers? Try searching our database.

Count tables and adding records

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scitea - 30 Sep 2008 14:33 GMT
Ok,

I have created a count-table to create records for journals that are
received where I work (Approx 42 different journals each month). The aim of
the database it to keep a record of when journals are due and what date they
actually arrive - mainly to help when it comes to renewing the subscription
so a report can be printed of the year, with a column for "overdue by (days)"

I have sorted the count table out, and using an Append query I have created
1500 'due date' records for each publication - this will allow reminders to
keep popping up for a few years to come.

The problem is this;

I have added another journal to the list and run the append query again, but
rather than creating the additional records that I wanted, it has duplicated
the current records, effectively doubling the data.

Is there a way to add another journal and append the results for just that
journal, not the whole fiippin lot?

Also, if we were to stop subscribing to a journal, is it possible to quickly
delete the records created for that journal in the table?

I hope so because this is all getting rather too complicated for me to handle!

Sci x
Allen Browne - 30 Sep 2008 14:51 GMT
To prevent duplicating the records, use a subquery in the WHERE clause of
your Append query statement.

INSERT INTO PubDue (...
SELECT ...
WHERE NOT EXISTS
   (SELECT PublicationID FROM PubDue AS Dupe
   WHERE (Dupe.PublicationID = 99) AND (Dupe.DueDate = #1/1/2008));

Hopefully you have enough SQL experience to match up the subquery to the
main record, replacing the literal place holders (99 and date) in the
example.

If subqueries are new, here's an introduction:
   http://allenbrowne.com/subquery-01.html

Regarding deletion, this might be a good candidate for cascading a delete.
In the Relationships window, you probably created a relation between  the
Publication table and the PubDue table. If you double-click this line and
check the boxes for Referential Integrity and for Cascading Delete, it will
automatically delete all PubDue records for that publication when you delete
it from the Publication table.

If you don't want to use cascading deletes, execute:
   DELETE FROM PubDue WHERE PublicationID = 99;

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Ok,
>
[quoted text clipped - 33 lines]
>
> Sci x
Scitea - 30 Sep 2008 16:20 GMT
Ok, I get it all apart from the PublicationID=99

What I have set up is a form to create the new record, then that leads to
another form to run the append query. The PublicationID is an autonumber, so
how do I enter it into the subquery so that it will change everytime the
records are updated without physically having to change the number?

This is all getting rather complicated! Thanks so much for your help!

Sci x

> To prevent duplicating the records, use a subquery in the WHERE clause of
> your Append query statement.
[quoted text clipped - 59 lines]
> >
> > Sci x
Allen Browne - 30 Sep 2008 23:20 GMT
When you enter a new publication into your form, Access assigns a new
PublicationID (autonumber.) I assume that you use the AfterInsert event
procedure of this form to insert the new records into the PubDue table.

Alternatively, if you are using a query drawing existing records from the
Publication table, and ensuring that each one has the desired records in the
PubDue table, then you already have the PublicationID in the main query. The
subquery can refer to that:
   WHERE Dupe.PublicationID = Publication.PublicationID
or whatever the tables/fields are called.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Ok, I get it all apart from the PublicationID=99
>
[quoted text clipped - 78 lines]
>> >
>> > Sci x
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.