Click to See Complete Forum and Search --> : Date...........
Rocks
Oct 12th, 2000, 06:21 AM
Hi all,
Need some help/advice on the following issue pls.
I would like to populate a combo box with value of the months.
I want the box to be populated with the month of September and October, and for the box to add the current month in automatically. i.e if I ran the app in December I would want all months from September to December to be populated in the box.
Any ideas please.
HunterMcCray
Oct 12th, 2000, 08:17 AM
Originally posted by Rocks
Hi all,
Need some help/advice on the following issue pls.
I would like to populate a combo box with value of the months.
I want the box to be populated with the month of September and October, and for the box to add the current month in automatically. i.e if I ran the app in December I would want all months from September to December to be populated in the box.
Any ideas please.
You need to use the Now() and DateDiff Functions in conjunction with the Format() Function:
combo1.clear
combo1.AddItem Format("mmmm",Now), Val(Format("m", Now)
combo1.AddItem Format("mmmm", DateAdd ("m", -1, Now)), Format("m", DateAdd ("m", -1))
combo1.AddItem Format("mmmm", DateAdd ("m", -2, Now)), Format("m", DateAdd("m", -2))
If you wanted to do more than a couple of months then you should use a for...next loop and replace the hard coded negative integers in the dateadd functions to your counter variable.
Hope This Helps
Hunter
Rocks
Oct 12th, 2000, 08:47 AM
Thanks for all the advice guys (and not leaving out gals),
but i have one more Q:
I am using a do while to populate the CBox.
I have a var m which holds a date. I want to add 1 month to the date ie. m = m + (1 Month(Date)).
what wouls the syntax be for the above????
any ideas..
Thanks,
HunterMcCray
Oct 12th, 2000, 11:06 AM
Originally posted by Rocks
Thanks for all the advice guys (and not leaving out gals),
but i have one more Q:
I am using a do while to populate the CBox.
I have a var m which holds a date. I want to add 1 month to the date ie. m = m + (1 Month(Date)).
what wouls the syntax be for the above????
any ideas..
Thanks,
Dim varNewDate
Dim varCurDate
varCurDate=Now
varNewDate=DateAdd("m", 1, varCurDate)
I also forgot the "Now" in two of my previous functions, it should have read:
combo1.clear
combo1.AddItem Format("mmmm",Now), Val(Format("m", Now)
combo1.AddItem Format("mmmm", DateAdd ("m", -1, Now)), Format("m", DateAdd ("m", -1, Now))
combo1.AddItem Format("mmmm", DateAdd ("m", -2, Now)), Format("m", DateAdd("m", -2, Now))
Sorry. To use it in a for...next loop
dim intX as Integer
combo1.clear
for intX=0 to 11
combo1.AddItem Format("mmmm", DateAdd ("m", -intX, Now)), Format("m", DateAdd ("m", -intX, Now))
next intX
Date Functions are intrinsic to VB and well documented, learn them, they are very helpful.
Hope it helps,
Hunter
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.