Link to home
Start Free TrialLog in
Avatar of MaeMcG
MaeMcG

asked on

Getting a field form my query into my database table

I created a query that found the date difference between two fields of my original table. I would like this date difference field to go into my original table as a new field/column - how would I go about doing this? Is the query necessary - is there someway I can paste this datediff formula into my Access table?
Avatar of pssandhu
pssandhu
Flag of Canada image

In Access add another column to your table in Design View and then under properties for that column, under DEFAULT enter the formula to calculate the difference between the 2 columns in the same table. Eveytime yuo insert or update the fields the new column should update automatically.
P.
Avatar of MaeMcG
MaeMcG

ASKER

Thank you so much for the quick reply - but unfortunately when I click properties under design view I only get "Default View" and do not just get "Default" (I am using Access 2003)... Also, is this the correct formula:
=DateDiff("d",[Date Opened],[Auto Report Date])

If those are the two fields I am looking to find the date difference between?

THANK YOU!
Yes, it is infact called "Default Value". Sorry for not being clear on that. Please insert your formula there and hopefully that should do it.
And yes, the formual looks fine.
P.
Avatar of MaeMcG

ASKER

Pssandhu - thank you, I will try that now. For my new column should I put the "Data Type" as a Date/Time, Number or Text? Thanks
I think number should be fine here. Also, if this does not work, we will have to create a number column of type number and then write an UPDATE query to update the value in that table. So let me know how it goes.
P.
Avatar of MaeMcG

ASKER

This screenshot (see attachment) keeps appearing when I do what you say... thanks again.
screenshot.JPG
ASKER CERTIFIED SOLUTION
Avatar of pssandhu
pssandhu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MaeMcG

ASKER

I pasted exactly what you said on the SQL View... do I need to have SELECT [Audit Issues] in first and then paste what you told me?

This did not update my fields in my original Audit Issues table, instead it created a column/field named "DAYS TO TARGET DATE" in the Query Datasheet View?

Thanks P.
screen-shot-2.JPG
Avatar of MaeMcG

ASKER

What I mean to say is that it does not do any calculation, but whatever I do type into Days to Target Date will autopopulate my field.

Thanks!
Avatar of MaeMcG

ASKER


SELECT [Audit Issues].[Auto Report Date], [Audit Issues].[Date Opened], DateDiff("d",[Date Opened],[Auto Report Date]) AS [Days To Target Date]
FROM [Audit Issues];
UPDATE [AUDIT ISSUES] SET [AUDIT ISSUES].[Days To Target Date] = DateDiff("d",[AUDIT ISSUES].[Date Opened],[AUDIT ISSUES].[Date Closed]);
First of all, when you run an update query you should get a pop up window saying "You are update these manu records" or somehting along the same line. You should not be seeing a datasheet view after you run the update query; all you will see are the pop windows as I described above.
And did you add the new column to the table without the default value? If you did then you should see an extra column with no values in that table when you open the table. The column should be of NUMBER datatype.
Also, are all the three column on the same table? What I mean is your "Date Opened", "Date Closed" and "Days to TargetDate" all on the same table? If not can you please explan what is the source table and how are the source and destination tables linked together.
No, you do not need a select statement before the update statement. The update statement should be al by itself.
Sorry for the delayed reply, I was stuck in a meeting.
P.
Avatar of MaeMcG

ASKER

How do I do the default value again - and how should I link the tables?

My original table is AUDIT ISSUES and I added a column/field "Days to Target Date"... I want the amount that my query (the one you gave me) to autofill or autopoulate into that column.

Thank you very much - and not a problem about being in the meeting. I'm a beginner here, so I appreciate your time and efforts in walking me through this.
MaeMcg,
Can you please reply back to my questions I asked above before we can proceed any further? I am reiterating them below:
1. Are all the three column on the same table? What I mean is your "Date Opened", "Date Closed" and "Days to TargetDate" all on the same table?
2. If not, then can you please explan what is the source table and how are the source and destination tables linked together.
Also, can you please give me the exact names of the tables and column we are dealing with so that when I provide you with a solution, you will just have to copy paste?
Thanks
P.