Solved

Month / Year Picker

Posted on 2004-09-30
8
911 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a task in Outlook from access 11 43
How to compare ms sql hashbytes results within vb6 5 105
Add and format columns in vb6 7 81
TT Auto Dashboard 13 104
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

742 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