Solved

Get Previous Month in VB6

Posted on 2006-06-13
3
457 Views
Last Modified: 2008-02-01
Experts,

I am writing a VB6 program and I would like to have it use previous month- instead of the current month.  The current syntax is:

txtDay.Value=Format(Now(), "dd")
txtMonth.Value=Format(Now(), "mm")
txtYEar.Value=Format(Now(), "yy")


I need to change the now() part to reflect the previous month.  Please advise.  I need to use the existing code.  Thanks!
0
Comment
Question by:jjrr007
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 16894738
txtDay.Value=Format(Now(), "dd")
txtMonth.Value=Format(dateadd("m", -1,Now()), "mm")
txtYEar.Value=Format(dateadd("m", -1,Now()), "yy")
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 16894746
>I need to change the now() part to reflect the previous month.  Please advise.  I need to use the existing code.  Thanks!

you would need to create a function called NOW() yourself returning the value of dateadd("m",-1,date())
0
 
LVL 9

Expert Comment

by:dancebert
ID: 16895063
What do you mean by 'previous month'?  angelIII gave you a solution for the same day of the month in the previous month.  For example if today is 6/13/06, his dateadd call will return 5/13/06.  But what if today 10/31/06?  There is no 9/31/06, the dateadd call will return 9/30/06.  Is that what you want?
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

12 Experts available now in Live!

Get 1:1 Help Now