Solved

Access VBA

Posted on 2013-12-17
2
234 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 51

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 48

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

707 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