Populate Two TextBox using a Single Pop-up Calendar

NoExcel

New Member
Joined
Jan 29, 2015
Messages
2
Hi! Newbie here!

I think this question has been posted several times and I have looked into different boards and threads but can't get my form to work properly.

Basically, I have a user form with two textbox and a command button for each. The command button will call the calendar form, where a MonthView calendar is. The user can pick the date on that calendar and the date "should" be placed on the textbox beside the command button that call the form.

But, I can't get the MonthView calendar to pass the date on the correct textbox. Either both are changing or only 1 is changing. I tried using a pass ByVal argument to identify which button called the calendar, but I'm getting more errors on this.

Textbox are called txtInvDate and txtInvDue. Correspondingly, their command buttons are called cmdInvDate and cmdInvDue.


Here's the code for the buttons. The effect here is that on the txtInvDue would change its date based on the date picked by the user.

PHP:
Private Sub cmdInvDue_Click()
Dim D As Integer
D = 1
Calender D:=A
Calender.Show
End Sub


PHP:
Private Sub cmdInvDue_Click()
Dim D As Integer
D = 2
Calender D:=A
Calender.Show
End Sub

Here's the command for the calendar to populate the textbox.

PHP:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)

If A = 1 Then
    POReceipt.txtInvDate.Value = MonthView1.Value
 '   A = 0
Else
    POReceipt.txtInvDue.Value = MonthView1.Value
   ' A = 0
End If
    
Unload Me
End Sub

What I'm trying to do is pass the value of D (from the command button) to A of the calender, so the calender would know which button called it.

I tried putting the code as

PHP:
Private Sub MonthView1_DateClick(ByVal DateClicked As Date, ByVal A As Integer)

This is giving me more errors instead.

Any idea on how I should code the passing of the value? or other method better than what I'm doing?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
This is how I handle that.

Pick a control and use the tag property to store the textbox control name. (Just about every control has one. Even the userform) I usually pick the broadest control within the group. For instance, if I had a frame around the textboxes, I would use the frame tag property. When the command button is clicked, I store the textbox name in the frame property.

Code:
[FONT=Courier New][COLOR=#007700]Private [/COLOR][COLOR=#0000bb]Sub cmdInvDue_Click[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]()
[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Me.Frame1.Tag = "TextBox1"
[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Calender[/COLOR][COLOR=#007700].[/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]Show
End Sub 
[FONT=Courier New][COLOR=#007700]Private [/COLOR][COLOR=#0000bb]Sub cmdInvDue2_Click[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]()
[/FONT][/COLOR][FONT=Courier New][COLOR=#0000bb]Me.Frame1.Tag = "TextBox2"
[/COLOR][COLOR=#0000bb]Calender[/COLOR][COLOR=#007700].[/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]Show
End Sub [/FONT][/COLOR][/FONT][/COLOR]
Then in the calendar control click event.
Code:
[FONT=Courier New][COLOR=#007700]Private [/COLOR][COLOR=#0000bb]Sub MonthView1_DateClick[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]ByVal DateClicked [/COLOR][COLOR=#007700]As [/COLOR][COLOR=#0000bb]Date[/COLOR][/FONT][FONT=Courier New][COLOR=#007700])

[/COLOR][/FONT][FONT=Courier New][COLOR=#0000bb]Me.Controls(Me.Frame1.Tag)[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]MonthView1[/COLOR][COLOR=#007700].[/COLOR][/FONT][COLOR=#0000bb][FONT=Courier New]Value
 [/FONT][/COLOR][COLOR=#007700][FONT=Courier New]    
[/FONT][/COLOR][COLOR=#0000bb][FONT=Courier New]Unload Me
End Sub [/FONT]
[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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