Solved

Month / Year Picker

Posted on 2004-09-30
8
907 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…

896 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

15 Experts available now in Live!

Get 1:1 Help Now