Solved

do while macro

Posted on 2014-01-19
7
285 Views
Last Modified: 2014-01-19
Hi,

I have a query with a set of records having a date field that I need to increment by 12 months leaving the day the same.  All records in the query need to have the date advanced 12 months so some sort of Do While not end-of-file would seem reasonable.  This needs to be done on a regular basis so I'll be placing a button in a form that runs a macro (preferred) or VBA or combo of both.  Is there a way to do this using macros only?  I prefer macros but I'll do whatever it takes to get this job done.

Help is appreciated.
Charlie
0
Comment
Question by:cwbarrett
  • 4
  • 3
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Not sure of you requirements here or your usage, ...but you can easily add a year to a data with something like this:

 DateAdd("yyyy",1,[YourDateField])
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
If you just need to "see" the next year, you can do this in a query:

SELECT ID, YourDateField,DateAdd("yyyy",1,[YourDateField]) AS AddYear
FROM YourTable.

If you want to actually "Change" the stored date, you can run a query like this:
    UPDATE YourTable SET YourTable.YourDateField = DateAdd("yyyy",1,[Yourdatefield]);
You can run this query directly:
Docmd.openquery "YourUpdateQueryName"

Or you can use code:
Currentdb.execute "UPDATE YourTable SET YourTable.YourDateField = DateAdd("yyyy",1,[Yourdatefield]);",dbfailonerror

Sample of both techniques attached, ...have fun.
;-)

JeffCoachman
Database55.mdb
0
 

Author Comment

by:cwbarrett
Comment Utility
Worked great!  Thank you!
Charlie
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Closing Comment

by:cwbarrett
Comment Utility
Solution was perfect.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Glad I could help!
;-)

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
...and you can see here for more info on the DateAdd function here:
http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx
0
 

Author Comment

by:cwbarrett
Comment Utility
Thanks, good info.  I have an old dbase (foxpro-DOS) app that I am trying to migrate to Access 2010.  I know what I need it to do, getting Access 2010 to do it sometimes proves difficult for me.  This web site has helped me for sure.
Charlie
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

10 Experts available now in Live!

Get 1:1 Help Now