[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1288
  • Last Modified:

Problem with VBA code to set label value

Hello,

I am using the below code to render the caption of a label. This has worked for most of the month but today it decided to not work.  Up until to day this label has read "Febuary". Now today it is reading "March". I can not figure out why this is happening.  Can you please help me with this. This currently in production and it is causing confusion for my people entering data.
Dim intMonth As Integer
intMonth = Month(Now)
.Form.lblcurrent.Caption = MonthName(Month(DateSerial(Year(Now), intMonth + 1, Day(Now))))

Open in new window

0
woodje
Asked:
woodje
  • 3
  • 2
1 Solution
 
Malik1947Commented:
are there any other parts of your code that change the label caption?
0
 
LimbeckCommented:
hm you are checking febr. 30th ;)

try using 1 instead of day(now)
0
 
Malik1947Commented:
use this code instead.



Dim intMonth As Integer
intMonth = Month(Now)
.Form.lblcurrent.Caption = MonthName(Month(Now) + 1)

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LimbeckCommented:
Malik, that wont work in december;woodje's code would if he uses

.Form.lblcurrent.Caption = MonthName(Month(DateSerial(Year(Now), intMonth + 1, 1)))

0
 
woodjeAuthor Commented:
That worked great and thanks for seeing the end of the year issue that was rough for last year.
0
 
LimbeckCommented:
glad to be of help :)

Ed.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now