Solved

Get Previous Month in VB6

Posted on 2006-06-13
3
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

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 143

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 …
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…
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…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

626 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