Solved

MS Access 2007 - Add time element to query/table

Posted on 2014-10-30
13
422 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 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

18 Experts available now in Live!

Get 1:1 Help Now