Userform with Calendar

LearnMeExcel

Well-known Member
Joined
Aug 11, 2009
Messages
746
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi
in my Userform i have 3 textBoxes
project_name
Date_From
Date_To
Code:
Private Sub Project_name_AfterUpdate()
Date_From.SetFocus
CalendarForm.Show
End Sub
Private Sub Date_From_AfterUpdate()
Date_To.SetFocus
CalendarForm.Show
End Sub
when calendar activate in Date_From
i whave this code
Code:
Private Sub Calendar1_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = 13 Then
    ProjectOfrm.Date_From.Value = Calendar1.Value
End If
Unload Me
End Sub
the problem is
when Calendar form activate in Date_To
what is the code to insert calendar date in it
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
i think the best solution to design two form for Calendars
to be the other code
Code:
Private Sub Calendar2_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
If KeyCode = 13 Then
    ProjectOfrm.Date_To.Value = Calendar1.Value
End If
Unload Me
End Sub

i wish if any one have another idea to add it here
 
Upvote 0
Put this in the UserForm module that has the three Textboxes (UserForm1 in this example)

Code:
Private Sub Project_name_AfterUpdate()

    Date_From.SetFocus
    CalendarForm.Caption = "Select Start Date"
    CalendarForm.Show
    
    Date_To.SetFocus
    CalendarForm.Caption = "Select End Date"
    CalendarForm.Show
    
End Sub

Put this in the CalendarForm module...
Code:
Private Sub Calendar1_Click()
    [COLOR="Red"]UserForm1[/COLOR].ActiveControl = Calendar1.Value
    CalendarForm.Hide
End Sub
 
Upvote 0
thanx Alpha
but there is problem
the first date insert in the first textbox "Project_name"
not in Date_From
The Second one insert in correct place in Date_To

the code in ProjectOfrm
Code:
Private Sub Project_name_AfterUpdate()

    Date_From.SetFocus
    CalendarForm.Caption = "Select Start Date"
    CalendarForm.Show
    
    Date_To.SetFocus
    CalendarForm.Caption = "Select End Date"
    CalendarForm.Show
    
End Sub

and in calendar form
Code:
Private Sub Calendar1_Click()
    ProjectOfrm.ActiveControl = Calendar1.Value
    CalendarForm.Hide
End Sub
what should i do ?
 
Upvote 0
Code:
Private Sub Project_name_AfterUpdate()
    Date_From.SetFocus
End Sub

Private Sub Date_From_Enter()
    CalendarForm.Caption = "Select Start Date"
    CalendarForm.Show
    Date_To.SetFocus
End Sub

Private Sub Date_To_Enter()
    CalendarForm.Caption = "Select End Date"
    CalendarForm.Show
End Sub

Code:
Private Sub Calendar1_Click()
    ProjectOfrm.ActiveControl = Calendar1.Value
    CalendarForm.Hide
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top