Results 1 to 4 of 4

Thread: Date...........

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137
    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.



    join me in the platinum

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    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



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137
    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,
    join me in the platinum

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    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




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width