Solved

do while macro

Posted on 2014-01-19
7
297 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
ID: 39792747
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
ID: 39792763
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
ID: 39793129
Worked great!  Thank you!
Charlie
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Closing Comment

by:cwbarrett
ID: 39793130
Solution was perfect.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39793144
Glad I could help!
;-)

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39793150
...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
ID: 39793345
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

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

831 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