Results 1 to 8 of 8
  1. #1
    Dexter is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    5

    Auto fill a due date column in a query


    Can anybody help me ?
    I'm pretty new to access but have a query (for correspondence) in which, among others, there are "date received", "type" of correspondence and "reply date" columns.
    What I now need is a column headed "Due Date" and wondered if there is an expression I could use whereby this column could be automatically populated, based on the entries in the "date received" column, but also to take into account the fact that the "type" column (i.e. kind of correspondence) would necessitate a different "due date".
    Ahy help would be greatly appreciated

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    ...but also to take into account the fact that the "type" column
    You will need a way to correlate the "type" with a number of days that should be added to the received date to calculate the due date. What I would typically do is to have a table that defines each type and the associated frequency (in days or whatever units that are needed)

    tblCorrespondenceTypes
    -pkCorrTypesID primary key, autonumber
    -txtCorrespondenceType
    -longFreq (the frequency in days, long number field)

    Then in your main table you would reference the correspondence type via a foreign key. Once the main table and the tblcorrespondenceTypes are related you can pull the information as necessary in a query to do the calculation

    SELECT dateadd("d",tblCorrespondenceTypes.longfreq, maintable.datereceived) as duedate
    FROM maintable INNER JOIN tblCorrespondenceTypes ON maintable.fkCorrTypesID=tblCorrespondenceTypes.pkC orrTypesID

  3. #3
    Dexter is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    5
    Hi
    Thanks for that, I have created the table with the fields "CorrTypesID", "Type" and "Num of Days" but don't know how to reference/relate the two tables.
    Also would I then enter
    "SELECT dateadd("d",tblCorrespondenceTypes.longfreq, maintable.datereceived) as duedate
    FROM maintable INNER JOIN tblCorrespondenceTypes ON maintable.fkCorrTypesID=tblCorrespondenceTypes.pkC orrTypesID" as an expression in a new field in the newly created query ?

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    A couple of suggestions first. Regarding the "Num of Days" field; it is generally recommended not to have spaces or special characters in your table or field names, so I would recommend changing "Num of Days" to NumofDays. Also, the word "Type" is a reserved word in Access, so I would recommend changing the field name to something else, perhaps CorrTypeName

    In your main table where you have the correspondence type, you will need to add a new long number field called fkCorrTypesID (the fk stands for foreign key) or something similar. Now you will have to update the fkCorrTypesID field in your main table with the appropriate CorrTypesID value from your new table that corresponds with the appropriate correspondence type. You can do this manually or via an update query. If you want to do an update query, the text of the correspondence field in your main table must exactly match the text in the "Type" field of your new table. If they do, then you will want to first make a backup copy of your database and then create a new query and bring in both your main table and your new table. Create a join between the two correspondence fields (the two text fields). Then change the query type from SELECT to Update. Add the fkCorrTypesID field to the query grid. In the Update to row put in the newtablename.CorrTypeID. I would recommend verifying the query by changing from the design grid view to SQL view.
    The SQL text of the query will look something like this (you will have to substitute your own table and field names):

    UPDATE tblMain INNER JOIN tblCorrespondenceTypes ON tblMain.CorrespondenceType = tblCorrespondenceTypes.CorrTypeName SET tblMain.fkCorrTypeID = [tblCorrespondenceTypes].[CorrTypeID];


    If you should see double quotes around the [tblCorrespondenceTypes].[CorrTypeID], please remove them.

    Run the query. Access should indicate that it is going to update some records.

    Go into the table and verify that the new field has been updated appropriately. Now you can remove the corresondence type field since you now have the ID field properly populated. Save the table.

    Go to the relationship window and establish a relationship between the two tables.

    Now when you create a query that has both tables you will have be able to add fields from either table.

    If you need additional help; please post back.

  5. #5
    Dexter is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    5
    Now I've got it and thanks a lot, just one more question, if you don't mind.
    Would I be able to highlight the "NumOfDays" field if the correspondence hasn't been completed in time (I.E. If I have a date received and the number of days for a particular correspondence type is exceeded).

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Yes, you would be able to highlight a control in a form that is bound to the field. You would not be able to do any highlighting at the table level.

    I'm guessing that you would have to run a little code in the on current event of the form that evaluates date received + the frequency and compares it to today's date (I assume). You will need the datediff() function most likely.

  7. #7
    Dexter is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    5
    O.K.
    That will do for me and thanks again !!!!!

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. Good luck with your project.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto Fill Issue #2
    By Swilliams987 in forum Database Design
    Replies: 9
    Last Post: 01-21-2011, 03:52 PM
  2. Auto-Fill
    By sophiecormier in forum Programming
    Replies: 3
    Last Post: 10-02-2010, 08:29 AM
  3. Replies: 1
    Last Post: 09-05-2010, 11:28 AM
  4. Auto-fill in datasheet
    By Terence in forum Database Design
    Replies: 2
    Last Post: 03-18-2010, 03:42 PM
  5. Auto fill a table?
    By newtoAccess in forum Access
    Replies: 3
    Last Post: 11-21-2009, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums