Solved

Access VBA

Posted on 2013-12-17
2
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

733 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