Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Previous Last day of Month
Brent Davis 
     
3 years ago
I would like to have a button that when clicked would move to the last day of the previous month each time. For example, I have an unbound text field with a date of 6-30-2023. When clicked i want it to go to 5-31-23. When clicked again i want to to go to 4-30-23. With the dateadd function it takes it back a month but the dates do not align with the last day of the month, click once it goes to 5-30-23 then to 4-30-23 then 3-30-23 and so on. I tried dateserial and it works on the first click but does not move past that date. I tried me.refresh, me.requery on the text box date field but it did not work. I am now just throwing stuff at it and hoping something works. But unfortunately nothing has so far. I am sure there is an easy fix but i am at a loss.  Any help is appreciated.
Scott Axton  @Reply  
        
3 years ago
Brent
I know it seems counter intuitive but you need to work with the current month first.  All months begin with the 1st. Correct?
So the easiest way is to go to the first day of this month then subtract 1 day.

This will work no matter the month or the year (leap year included).  See screen shot below.


Scott Axton  @Reply  
        
3 years ago

Alex Hedley  @Reply  
           
3 years ago
Scott Axton  @Reply  
        
3 years ago
Alex - I forgot about that one.  Nice!!
Brent Davis OP  @Reply  
     
3 years ago
Thanks guys for your replies.  I understand how to get the last day of each month but I want to be able to click a button and have it go back to the last day of the previous month after each click like Richard does with a day or a week with the + - buttons he creates in the Date Buttons video. If the date in the text box is 6-30-23, when I click the button I want it to go to 5-31-23, when clicked again I want it to go to 4-30-23, etc.  How do I do that?
Kevin Robertson  @Reply  
          
3 years ago
Add this to the Click() event of your button to go to the last day of the previous month.
Change 'YourDate' to the name of your Text Box / Date field.

YourDate = DateSerial(Year(YourDate), Month(YourDate), 0)

DateSerial
Brent Davis OP  @Reply  
     
3 years ago
Thanks Kevin. That is what I tried first but it only takes me back to the next previous month. If I click it again it just stays on the same date, it does nothing. What am I missing?
Brent Davis OP  @Reply  
     
3 years ago
For instance, text box date is 6-30-23, click button it takes me to 5-31-23, click again and it stays on 5-31-23.
Brent Davis OP  @Reply  
     
3 years ago
I want the text box to show 4-30-23, then 3-31-23, etc   Each time I click it I want the last day of previous month to show in the text box
Brent Davis OP  @Reply  
     
3 years ago
Kevin, my apologizes. You are 100% correct! In my haste to reply i did not pay attention to your solution, which is absolutely correct!  I will be more thorough next time. Again, my apologizes and thanks for your assistance.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/8/2026 6:53:55 PM. PLT: 1s