Results 1 to 16 of 16

Thread: Calendar control on User Form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Calendar control on User Form

    Morning Everyone,

    Is there anyone out there that could give me a little help with a calendar control I have on a User Form.

    My form is relatively simple and has 4 text boxes on the left and 4 combo boxes on the right. I would like users to add information on the left in the text boxes and then select a date for this on the right in the combo box. At the moment I have the calendar control on Form 2. I am able to .show the form when the combo box is clicked on but I have no idea how to get the date back into the combo box, apart from linking it directly but I would like to use the calendar with each combo box! If anyone could give me an idea or a snipet of code or even some advice if I'm going about it the wrong way that would be great. Thank you all.

    Jose

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Calendar control on User Form

    Are you doing this in Outlooks VBA or on VB 6 Forms?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    On a VB6 Form

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calendar control on User Form

    Then you should be using the MonthView not the Calendar control as that was made more for VBA UserForms than VB6 Forms and will exhibit odd behavior if used in VB6.

    Quote Originally Posted by Jose001
    My form is relatively simple and has 4 text boxes on the left and 4 combo boxes on the right. I would like users to add information on the left in the text boxes and then select a date for this on the right in the combo box. At the moment I have the calendar control on Form 2. I am able to .show the form when the combo box is clicked on but I have no idea how to get the date back into the combo box
    I'm confused. What is in your combo box? You mention Form2. What is on Form2 and I'm assuming there is a Form1. What is on Form1? What is it that you are trying to do with the dates?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    Sorry for any confusion guys, I'm working this out as I go along. I put a combo box because I wanted the calendar to popup when the date field was clicked on. There are basically four text boxes labelled 1 - 4. I would like another box next to each one which the user can click on and a calendar popup. When they select the date it is dropped back into that box they clicked on. I dont know what would be the best way to do this but it has to be a popup calendar. How would I go about using the month view? Thanks for you help guys

  6. #6
    Lively Member
    Join Date
    Oct 2004
    Location
    carmi,IL.
    Posts
    105

    Re: Calendar control on User Form

    Hello:

    Would the (DTpicker) be a better choice? (Date Time Picker!)

    If your just wanting to select a Date: this sounds like what you might be looking for.
    David M. Camp

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    It is and I've tried this and it works a treat...except...users enter dates to correspond with events which they enter in the text box to the left. The DTPicker automatically sets itself to todays date. So when I use the information say in an excel spreadsheet it draws through the date next to an empty cell. I hope that makes sense. I guess I need it to be empty unless someone clicks on a date. I've been through the DTPicker properties and it will only let me set it to null if I enable some kind of checkbox. But then when I use data it inserts a time next to the date! I feel like screaming lol

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    I still think the calendar is my best option but have no idea how to make it neutral, i.e on a second form which is shown when the user clicks on a text/combo box and then how to feed that date back to the box?

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calendar control on User Form

    In the click event of the control (text/combo) do a
    Code:
    Form2.Show
    In the click event of the calendar control, do a
    Code:
    Form1.Text1.Text = Calendar.Value

  10. #10
    Lively Member
    Join Date
    Oct 2004
    Location
    carmi,IL.
    Posts
    105

    Re: Calendar control on User Form

    Quote="But then when I insert data it puts a time next to the date."


    This will format the dtpicker to the (short date)
    FormatDateTime(DTPicker1.Value, vbShortDate)
    David M. Camp

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    Hey Hack, Thanks for replying, will this not link the calender to this text box though. There are four boxes which may need to use the calender, will this still work?

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calendar control on User Form

    Then you will need to develop a way of telling the calendar which box to place the date in. Try creating a form level string....something like
    Code:
    Private strTextBox As String
    In the click event of each textbox, and before the Form2.Show, put
    Code:
    strTextBox = "NameOfTextBox"
    Then, on in the Calendar on Form2, do
    Code:
    Select Case strTextBox
             Case "Text1"
             Form1.Text1.Text = Calendar.Value
             Case "Text2"
              Form1.Text2.Text = Calendar.Value
             Case "Text3"
              Form1.Text3.Text = Calendar.Value
             Case "Text4"
             Form1.Text4.Text = Calendar.Value
    End Select

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    Thank you thankyou Hack I'm gonna try this now and will let you know how it goes! Thanks mate

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Re: Calendar control on User Form

    Hey Hack,

    Not sure what I'm doing wrong but don't seem to be able to get this code working, am I making an extremely elementary error here is the code from UserForm1

    vb Code:
    1. Private strComboBox As String
    2.  
    3. 'strTextBox = "NameOfTextBox"
    4.  
    5. Private Sub ComboBox1_Change()
    6. strTextBox = "ComboBox1"
    7. UserForm2.Show
    8. End Sub
    9.  
    10.  
    11. Private Sub ComboBox2_Change()
    12. strTextBox = "ComboBox2"
    13. UserForm2.Show
    14. End Sub
    15.  
    16. Private Sub ComboBox3_Change()
    17. strTextBox = "ComboBox3"
    18. UserForm2.Show
    19. End Sub
    20.  
    21. Private Sub ComboBox4_Change()
    22. strTextBox = "ComboBox4"
    23. UserForm2.Show
    24. End Sub
    25.  
    26. Private Sub UserForm_Click()
    27.  
    28. End Sub

    and here is the code from UserForm2

    vb Code:
    1. Private Sub CommandButton1_Click()
    2. Select Case strComboBox
    3.          Case "ComboBox1"
    4.          UserForm1.ComboBox1.Text = Calendar1.Value
    5.          Case "TComboBox2"
    6.           UserForm1.ComboBox2.Text = Calendar1.Value
    7.          Case "ComboBox3"
    8.           UserForm1.ComboBox3.Text = Calendar1.Value
    9.          Case "ComboBox4"
    10.          UserForm1.ComboBox4.Text = Calendar1.Value
    11. End Select
    12. End Sub

    I changed it to combo boxes because I couldnt get the onClick to work with a basic textbox.

    Jose

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Calendar control on User Form

    Are you sure its VB 6 because VB 6 doesnt have "Private Sub UserForm_Click()" UserForm events, VBA does.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calendar control on User Form

    Also, don't put the code in the Change event. Move it to the Click event.

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