Solved

MS Access 2007 - Add time element to query/table

Posted on 2014-10-30
13
437 Views
Last Modified: 2014-10-31
EE,
I have an Access 2007 database.
I ship using UPS WorldShip.
When UPS WorldShip processes a shipment label it exports the tracking number and estimated delivery date (formatted as: 20141104 - Nov. 4, 2014 - for example) into a table (UPS_Tracking_Info) in Access.

I would like to send customers a (mail merge) email after two weeks asking them to fill out a brief 2 or 3 question  survey of what they purchased.

The query that I would need to join the UPS_Tracking_Info, Orders, and Customers table I can take care of. What I would like to know is if there is a way to add 14 days to the delivery_estimate field (delivery_estimate + 14)?

Is there a way of doing this?

Any help would be greatly appreciated.
dresdena1
0
Comment
Question by:dresdena1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40414378
You can use:

DateAdd("d", 14, delivery_estimate) to get that date you want.

DateAdd ( interval, number, date )

For more examples and options, see: http://www.techonthenet.com/access/functions/date/dateadd.php
0
 

Author Comment

by:dresdena1
ID: 40414409
eghtebas,
Thank you for the prompt response.

In the UPS_Tracking_Info table, the delivery_estimate field is text.

I made a copy of the table and tried to change the field from text to date/time and I got a data type mismatch error and it deleted all of the data in the delivery_estimate field.

Is there a way to convert it?

Thanks,
dresdena1
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40414438
use CDate() function.

DateAdd("d", 14, CDate(delivery_estimate))
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 37

Expert Comment

by:PatHartman
ID: 40414610
The UPS date format is not one that Access recognizes so you need to convert the string to something Access will recognize as a date first.

DateAdd("d", 14, DateSerial(Left(delivery_estimate, 4), mid(delivery_estimate, 5, 2), right(delivery_estimate, 2) )
0
 

Author Comment

by:dresdena1
ID: 40414614
eghtebas,
I have a query. It has joins from UPS_Tracking_Info, Orders, and Customers.
In the query I have the customers name, email, order_number, tracking_number, and delivery_estimate

When I look at it in Design view I see the queried fields. When I put DateAdd("d", 14, CDate(delivery_estimate)) in the Criteria Field of delivery_estimate I get a "Data type mismatch in criteria expression" error.

In the UPS_Tracking_Info table where delivery_estimate is found I would not know how to apply a function to it.

Any help would be greatly appreciated.
Thanks.
dresdena1
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40414658
I see, because the format is like 20141104,

For conversion purpose, use as stated by Pat:

DateAdd("d", 14, DateSerial(Left(delivery_estimate, 4), mid(delivery_estimate, 5, 2), right(delivery_estimate, 2) )
0
 

Author Comment

by:dresdena1
ID: 40414677
eghtebas and PatHartman,
Thank you, but where should I use this?


dresdena1
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 40414776
in the query that selects the customers you want to contact.

Select ...
From ...
Where SomeDate = DateAdd("d", 14, DateSerial(Left(delivery_estimate, 4), mid(delivery_estimate, 5, 2), right(delivery_estimate, 2) )
0
 

Author Comment

by:dresdena1
ID: 40414926
PatHartman,
When I add the Where statement, I get a syntax error message for a missing ) or ]

When I add a ) to the end and try to run it I am prompted with a box to "Enter Parameter Value"   for SomeDate.
 
If I press Enter I get an error that the "expression is typed incorrectly or is too complex to be evaluated..."

I don't know if it will help, but I will paste the SELECT statement below:

SELECT Customers.[First Name], Customers.[Last Name], Customers.[Email Address], UPS_Tracking_Info.OrderNo, UPS_Tracking_Info.TrackingNo, UPS_Tracking_Info.complete, UPS_Tracking_Info.delivery_estimate
FROM (Customers INNER JOIN [Order Table] ON Customers.[Customer ID] = [Order Table].[Customer ID]) INNER JOIN UPS_Tracking_Info ON [Order Table].OrderNo = UPS_Tracking_Info.OrderNo
WHERE SomeDate = DateAdd("d", 14, DateSerial(left(delivery_estimate, 4), mid(delivery_estimate, 5, 2), right(delivery_estimate, 2) ))

Thank you for all of the help.
dresdena1
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40414944
I tested the following and it works:

MyDate: DateAdd("d",14,DateSerial(Left("20140909",4),Mid("20140909",5,2),Right("20140909",2)))

Replace "20140909" with your data field.
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40415145
It is easier and faster the other way around:

SELECT
    Customers.[First Name],
    Customers.[Last Name],
    Customers.[Email Address],
    UPS_Tracking_Info.OrderNo,
    UPS_Tracking_Info.TrackingNo,
    UPS_Tracking_Info.complete,
    UPS_Tracking_Info.delivery_estimate
FROM
    (Customers INNER JOIN
    [Order Table]
        ON Customers.[Customer ID] = [Order Table].[Customer ID]) INNER JOIN
        UPS_Tracking_Info
            ON [Order Table].OrderNo = UPS_Tracking_Info.OrderNo
WHERE
    UPS_Tracking_Info.delivery_estimate = Format(DateAdd("d", -14, Date()), "yyyymmdd")

/gustav
0
 

Author Closing Comment

by:dresdena1
ID: 40415366
Thank you to everyone for all of the help.
Gustav Brock I put your query in and it worked perfectly the first time!
Thank you all again for all of the help!
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40415372
You are welcome!

/gustav
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question