Solved

Get Previous Month in VB6

Posted on 2006-06-13
3
459 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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