473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Date Funtions for Previous & Next Buttons On Form

I have the start and end dates on my report forms set at the first and last days of the current month.
I also have three buttons for these dates:
One that advances forward one month at a time
One that goes back one month at a time
One that returns to the current month (same code as I use in "OnLoad")
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandBack_Click()
  2. Me.DateStart = DateSerial(Year(Me.DateStart), Month(Me.DateStart) - 1, 1)
  3. Me.DateEnd = DateAdd("m", 1, (DateAdd("d", -1, DateStart)))
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandCurrent_Click()
  2. Me.DateStart = DatePart("m", Now()) & "/01/" & DatePart("yyyy", Now())
  3. Me.DateEnd = DateSerial(Year(Date), Month(Date) + 1, 1) - 1
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandForward_Click()
  2. Me.DateStart = DateSerial(Year(Me.DateStart), Month(Me.DateStart) + 1, 1)
  3. Me.DateEnd = DateSerial(Year(DateStart), Month(DateStart) + 1, 1) - 1
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me.DateStart = DatePart("m", Now()) & "/01/" & DatePart("yyyy", Now())
  3. Me.DateEnd = DateSerial(Year(Date), Month(Date) + 1, 1) - 1
  4. End Sub
Nov 18 '19 #1
4 2019
twinnyfo
3,653 Expert Mod 2GB
JEBritt,

Welcome to Bytes!

Is this a question or an attempt at an informative article?
Nov 18 '19 #2
NeoPa
32,556 Expert Mod 16PB
Indeed. It's not clear where you're going with this thread.
Nov 19 '19 #3
cactusdata
214 Expert 128KB
By all means, avoid string handling of date and time.
Thus, your code can be reduced to:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandBack_Click()
  2.     Me.DateStart = DateSerial(Year(Me.DateStart), Month(Me.DateStart) - 1, 1)
  3.     Me.DateEnd = DateSerial(Year(Me.DateStart), Month(Me.DateStart), 0)
  4. End Sub
  5.  
  6. Private Sub CommandCurrent_Click()
  7.     Me.DateStart = DateSerial(Year(Date), Month(Date), 1)
  8.     Me.DateEnd = DateSerial(Year(Date), Month(Date) + 1, 0)
  9. End Sub
  10.  
  11. Private Sub CommandForward_Click()
  12.     Me.DateStart = DateSerial(Year(Me.DateStart), Month(Me.DateStart) + 1, 1)
  13.     Me.DateEnd = DateSerial(Year(DateStart), Month(DateStart) + 2, 0)
  14. End Sub
  15.  
  16. Private Sub Form_Load()
  17.     Me.DateStart = DateSerial(Year(Date), Month(Date), 1)
  18.     Me.DateEnd = DateSerial(Year(Date), Month(Date) + 1, 0)
  19. End Sub
Nov 19 '19 #4
just information I thought some might find useful.
Feb 18 '20 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Psybar Phreak | last post by:
hi all, im developing a site in perl with mason on a postgreSQL backend. i currently have a page that lists all items in a table, but would like to do the " << PREVIOUS 1 2 3 4 NEXT>> "...
2
by: eeh | last post by:
Hi, Suppose I have a table "product" with fields id,name,price. I want to get a resultset of previous and current and next record when the resultset is sorted by id and id=10. The table data is...
3
by: suveetha | last post by:
I would like to know in javascript how to wirte a code from moving one page to another ie. in my html page i have two frames , the first frame consist of previous and next button , in the second...
3
by: anejamanish | last post by:
Hi guys I am developing a website using php and ajax. Here I need to to design previous and next buttons to load new html files with every click. I am displaying these files within a div tag....
14
imrosie
by: imrosie | last post by:
Hello, I have a app that allows for searching of images by stored (links) name. The absolute path to the images is what's stored. Not the image. Located at the bottom of the form is a previous...
3
by: md9108 | last post by:
I have a previous page and next page coded. The next page works. The previous page gives me an http: 404 error and I can't figure it out. The error is on the line "<td align=left> <!-- ...
11
by: simon2x1 | last post by:
i have 3 pages,home.php, next.php page and other.php.in the home.php page i selected name from the database and i gave it a limit and also an if statement to echo next.for the next.php page and...
1
by: akrao | last post by:
i want a simple java script code for previous and next buttons. my scenario is i want to display one panel at a display time . fisrt default first panel displays remaining are not visible and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.