|
-
Aug 2nd, 2007, 04:40 AM
#1
Thread Starter
Junior Member
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
-
Aug 2nd, 2007, 04:44 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 2nd, 2007, 04:52 AM
#3
Thread Starter
Junior Member
Re: Calendar control on User Form
-
Aug 2nd, 2007, 05:29 AM
#4
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.
 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?
-
Aug 2nd, 2007, 05:40 AM
#5
Thread Starter
Junior Member
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
-
Aug 2nd, 2007, 06:27 AM
#6
Lively Member
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.
-
Aug 2nd, 2007, 06:31 AM
#7
Thread Starter
Junior Member
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
-
Aug 2nd, 2007, 06:34 AM
#8
Thread Starter
Junior Member
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?
-
Aug 2nd, 2007, 06:57 AM
#9
Re: Calendar control on User Form
In the click event of the control (text/combo) do aIn the click event of the calendar control, do a
Code:
Form1.Text1.Text = Calendar.Value
-
Aug 2nd, 2007, 07:10 AM
#10
Lively Member
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)
-
Aug 2nd, 2007, 07:59 AM
#11
Thread Starter
Junior Member
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?
-
Aug 2nd, 2007, 08:05 AM
#12
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
-
Aug 2nd, 2007, 08:10 AM
#13
Thread Starter
Junior Member
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
-
Aug 2nd, 2007, 08:50 AM
#14
Thread Starter
Junior Member
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:
Private strComboBox As String
'strTextBox = "NameOfTextBox"
Private Sub ComboBox1_Change()
strTextBox = "ComboBox1"
UserForm2.Show
End Sub
Private Sub ComboBox2_Change()
strTextBox = "ComboBox2"
UserForm2.Show
End Sub
Private Sub ComboBox3_Change()
strTextBox = "ComboBox3"
UserForm2.Show
End Sub
Private Sub ComboBox4_Change()
strTextBox = "ComboBox4"
UserForm2.Show
End Sub
Private Sub UserForm_Click()
End Sub
and here is the code from UserForm2
vb Code:
Private Sub CommandButton1_Click()
Select Case strComboBox
Case "ComboBox1"
UserForm1.ComboBox1.Text = Calendar1.Value
Case "TComboBox2"
UserForm1.ComboBox2.Text = Calendar1.Value
Case "ComboBox3"
UserForm1.ComboBox3.Text = Calendar1.Value
Case "ComboBox4"
UserForm1.ComboBox4.Text = Calendar1.Value
End Select
End Sub
I changed it to combo boxes because I couldnt get the onClick to work with a basic textbox.
Jose
-
Aug 2nd, 2007, 12:10 PM
#15
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 2nd, 2007, 12:11 PM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|