Solved

Get Previous Month in VB6

Posted on 2006-06-13
3
458 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

11 Experts available now in Live!

Get 1:1 Help Now