Solved

Month / Year Picker

Posted on 2004-09-30
8
903 Views
Last Modified: 2010-05-19
Looking for something like DTPicker but only for Month / Year combo.

Thanks in advance,
-Alex
0
Comment
Question by:AlexF777
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12189471
You need to specify a custom formatting string, take a look to this previous question:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20119599.html
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 150 total points
ID: 12189487
Private Sub Form_Load()
    DTPicker1.Format = dtpCustom
    DTPicker1.CustomFormat = "MM/yyyy"
    DTPicker1.UpDown = True
End Sub
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12189755
This is a code solution, I hope it helps:

Create a new VB standard project with a single form (Form1). Place a ComboBox (Combo1) on it and set the style to 2 (Dropdown Listbox). Place the following code in the form:

--------------------
Option Explicit

Private Sub Combo1_Click()
    '*** Test code
    If Combo1.ListIndex > -1 Then
        MsgBox "You selected " & Format$(Combo1.ItemData(Combo1.ListIndex), "yyyy mm")
    End If
    '*** /Test code
End Sub

Private Sub Form_Load()
    '*** Test code
    FillMonthYearCombo Combo1, #3/1/2002#, Now
    '*** /Test code
End Sub

Private Sub GetMonthYear(ByVal MYdate As Date, ByRef MYmonth As Integer, ByRef MYYear As Integer)
    MYmonth = DatePart("m", MYdate)
    MYYear = DatePart("yyyy", MYdate)
End Sub

Private Sub AddMonthYearItem(cboMonthYear As ComboBox, ByVal nd As Date)
    With cboMonthYear
        .AddItem Format$(nd, "mmmm yyyy")
        .ItemData(.NewIndex) = CLng(nd)
    End With
End Sub

Private Function FillMonthYearCombo(cboMonthYear As ComboBox, ByVal StartDate As Date, ByVal EndDate As Date)
    Dim sm As Integer
    Dim sy As Integer
    Dim em As Integer
    Dim ey As Integer
    Dim yl As Integer
    Dim ml As Integer

    cboMonthYear.Clear

    If StartDate > EndDate Then
        Exit Function
    End If

    GetMonthYear StartDate, sm, sy
    GetMonthYear EndDate, em, ey

    If ey = sy Then
        For ml = sm To em
            AddMonthYearItem cboMonthYear, DateSerial(sy, ml, 1)
        Next
    Else
        For ml = sm To 12
            AddMonthYearItem cboMonthYear, DateSerial(sy, ml, 1)
        Next
        For yl = sy + 1 To ey - 1
            For ml = 1 To 12
                AddMonthYearItem cboMonthYear, DateSerial(yl, ml, 1)
            Next
        Next
        For ml = 1 To em
            AddMonthYearItem cboMonthYear, DateSerial(ey, ml, 1)
        Next
    End If
End Function

--------------------
0
 

Author Comment

by:AlexF777
ID: 12190720

I like mladenovicz's solution, only would be good if my month could stay between 1 and 12

Thank You,
-Alex
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Expert Comment

by:Erick37
ID: 12190861
I think the correct format string is:

DTPicker1.CustomFormat = "MM/yyy" '<< 3 y's, not 4

Then the month will cycle correctly
0
 

Author Comment

by:AlexF777
ID: 12191011
somehow, month is varying between 00 and 59 and then goes back to 0 ...
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 100 total points
ID: 12191049
Make sure month is "MM" and not "mm"

"MM" is month
"mm" is minutes
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12191054
works fine for me (month is between 1 and 12).

are you sure you are using

 DTPicker1.CustomFormat = "MM/yyyy"

not

 DTPicker1.CustomFormat = "mm/yyyy"
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now