Solved

Access VBA

Posted on 2013-12-17
2
221 Views
Last Modified: 2013-12-17
I have to fields, EndDate and StartDate. I want StartDate to be updated with the beginning of the month 18 months prior to the date I enter in EndDate. How do I do that?

This is my current code, which returns 30-Mar-12 if I enter 30-Sep-13. I would like to have 1-Mar-12 returned


Private Sub EndDate_LostFocus()

StartDate.Value = DateAdd("m", -18, [EndDate].Value)

End Sub
Private Sub EndDate_LostFocus()

StartDate.Value = DateAdd("m", -18, [EndDate].Value)

End Sub

Open in new window

0
Comment
Question by:fitaliano
2 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
ID: 39723924
Hi

pls try

DateSerial(Year(DateAdd("m", -18, [EndDate].Value)), Month(DateAdd("m", -18, [EndDate].Value)), 1)

Regards
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 250 total points
ID: 39723932
How about:

StartDate.Value = DateSerial(Year([EndDate].Value), Month([EndDate].value) - 18, 1)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

757 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

23 Experts available now in Live!

Get 1:1 Help Now