Solved

MS Access 2007 - Add time element to query/table

Posted on 2014-10-30
13
427 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 33

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 33

Expert Comment

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

DateAdd("d", 14, CDate(delivery_estimate))
0
 
LVL 34

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 33

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

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


dresdena1
0
 
LVL 34

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 33

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now