Solved

MS Access 2007 - Add time element to query/table

Posted on 2014-10-30
13
431 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 35

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 35

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 49

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 49

Expert Comment

by:Gustav Brock
ID: 40415372
You are welcome!

/gustav
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

840 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