Solved

Access VBA

Posted on 2013-12-17
2
226 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 49

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

810 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