Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MonthView Control (VB6)

    Hi all. I have a form with about 20 date fields on it. What I am trying to achieve is for the user to be able to click on the date field and a calender similiar to the MonthView Control will popup and the user will select a date from it. When the user tabs out of the field the date will display in the pre-determined format (YYYY-MM-DD). Currently all I have is the MonthView control on the form and it takes up alot of space.
    Is this possible to acheive?

    Thanks.

    Bill

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: MonthView Control (VB6)

    How 'bout the DTPicker, from "Microsoft Windows Common Controls-2 6.0" AKA MSCOMCT2.OCX? It pops down when the user clicks the drop-down arrow. (You will undoubtedly choose a font that actually fits inside the space you allot to it, unlike my example.)

  3. #3
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    jscher2000 - Perfect! Thanks for your help.

    Bill

  4. #4
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Oops just one other thing. When I run the form with the DTPicker field on it, the field displays todays date. I want the field to remain blank until it is clicked on. When I go to the Value property and delete the displayed date with the intention of forcing the field to display as blank, I get an error message saying that the field cannot contain a Null value.
    Is there anyway to get the field to display as blank until a date is selected? Thanks for your help.

    Bill

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

  6. #6
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Thanks heaps. The following works which I got from your second URL:

    Private Sub dpkDepDate1_Change()

    If dpkDepDate1.Value <> "" Then
    dpkDepDate1.Format = dtpShortDate
    End If

    End Sub


    Private Sub Form_Load()
    'First, set date to today... then blankout dpkDepDate1
    dpkDepDate1.Format = dtpCustom
    dpkDepDate1.CustomFormat = " ' "

    End Sub

    Just one more thing. I have 10 fields which the code needs to apply named dpkDepDate1 through to dpkDepDate10. Is there anyway I can write one piece code that will apply to all 10 fields instead of writing the same code 10 times?
    Thanks as always.

    Bill

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Private Sub dpkDepDate1_Change()
    HandleDateChange 1
    End Sub

    Private Sub dpkDepDate2_Change()
    HandleDateChange 2
    End Sub

    ' etc. for dkpDepDate3_Change through dkpDepDate10)Change

    Private Sub HandleDateChange(i As Integer)
    If Me.Controls("dpkDepDate" & i).Value <> "" Then
    Me.Controls("dpkDepDate" & i).Format = dtpShortDate
    End If
    End Sub

    Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 10
    'First, set date to today... then blankout dpkDepDate #i
    Me.Controls("dpkDepDate" & i ).Format = dtpCustom
    Me,Controls("dpkDepDate" & i).CustomFormat = " ' "
    Next i
    End Sub

  8. #8
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    For some reason the following lets the date picker come up but when you click/tab out of it, no date is displayed:

    Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 10
    'First, set date to today... then blankout dpkDepDate #i
    Me.Controls("dpkDepDate" & i ).Format = dtpCustom
    Me,Controls("dpkDepDate" & i).CustomFormat = " ' "
    Next i
    End Sub

    Any idea why? I have had a little play with it and can't work out why.
    Thanks for your help.

    Bill

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    There is a typo in my reply that the Visual Basic Editor should catch: "Me," instead of "Me." I just typed the code into the reply, I didn't copy it from actual code.

    The Form_Load part only blanks the Date/Time pickers. Displaying the dates is taken care of in the ..._Change events, In my example, they all call HandleDateChange. I just now tried it in an actual form and it works OK.

  10. #10
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    Got it. Works fine. Thanks heaps for your help.

    Bill

  11. #11
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    I have a form which emulates the MonthView control. You're welcome to use it. Instructions for calling its functions are at the top of the code. I usually put a small button next to the textbox which actually calls this form, but you can certainly use a textbox's click or double-click event to call it. Feel free to try it and e-mail with any questions.

  12. #12
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    I actually have two sets of 10 date fields that use the MonthView Control on the same form. They are dtpDepDate1 through 10 and dtpArrDate1 through 10 respectively. I got the code to work fine when changing dtpDepDate1 - 10 but I cannot change both sets. When I run the form with the code changed I get an Ambigous Name Detected error on the second Form Load Sub.
    Any idea where I have gone wrong?
    Thanks heaps.

    Bill

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    There cannot be two procedures of the same name in a module. In particular, there can only be one Form_Load procedure for a given form - otherwise, which one should be executed when the form opens?

    You can, however, initialize both sets of date fields in one procedure:

    Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 10
    Me.Controls("dpkArrDate" & i ).Format = dtpCustom
    Me,Controls("dpkArrDate" & i).CustomFormat = " ' "
    Me.Controls("dpkDepDate" & i ).Format = dtpCustom
    Me,Controls("dpkDepDate" & i).CustomFormat = " ' "
    Next i
    End Sub

  14. #14
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    Sorry for the late reply but I have been traveling. Since your last post I have had to start again with my app, as I have established that I didn't plan well enough initially - lesson learnt! Despite having to start again, my original problem remains, however the fields have changed. In review my problem is this.
    I have a form with quite a few sets of fields. They are:

    dtpArrDate1 through to dtpArrDate10
    dtpDepDate1 through to dtpDepDate10
    dtpCheckInDate1 through to dtpCheckInDate5
    dtpCheckOutDate1 through to dtpCheckOutDate5
    dtpCarPickUp1 through to dtpCarPickUp5
    dtpCarDropOff1 through to dtpCarDropOff5

    The fields are all date picker controls. Currently when the form is loaded the fields display today's date which is not what I want. I want the fields to display as blank until the user actually selects a date. I have had a few goes at writing code to make this happen but never successfully. I also tried to manipulate the code you supplied so generously previously but the changes I have had to make to the app have made it redundant and my skills are not up to scratch programming wise.
    Any ideas for code which will achieve my aim?

    Thanks in advance.

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Are you sure that having 40 Date/Time pickers on a form is a good idea?

    I would think that adapting the code would be straightforward:

    Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 10
    Me.Controls("dpkArrDate" & i ).Format = dtpCustom
    Me,Controls("dpkArrDate" & i).CustomFormat = " ' "
    Me.Controls("dpkDepDate" & i ).Format = dtpCustom
    Me,Controls("dpkDepDate" & i).CustomFormat = " ' "
    Next i
    For i = 1 To 5
    Me.Controls("dtpCheckInDate" & i ).Format = dtpCustom
    Me.Controls("dtpCheckInDate" & i ).CustomFormat = " ' "
    Me,Controls("dtpCheckOutDate" & i).Format = dtpCustom
    Me,Controls("dtpCheckOutDate" & i).CustomFormat = " ' "
    Me.Controls("dtpCarPickUp" & i ).Format = dtpCustom
    Me.Controls("dtpCarPickUp" & i ).CustomFormat = " ' "
    Me,Controls("dtpCarDropOff" & i).Format = dtpCustom
    Me,Controls("dtpCarDropOff" & i).CustomFormat = " ' "
    Next i
    End Sub

    If this doesn't work, an you explain where you have problems?

Page 1 of 2 12 LastLast

Posting Permissions

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