Excel VBA pass a forms value in other opened form

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

Scenario:-

First Form Name:- GenerateRequest
Second Form Name:- DatePickerForm

Form "GenerateRequest" Controls:- A Button (Name:- cmddate), A TextBox (Name:- TextBox1)
Form "DatePickerForm" Controls:- Other user friendly controls For Selecting a date, A Button (Caption:- "OK")



In the form "GenerateRequest" , clicking on the button "cmddate", show's the form "DatePickerForm" (this form is a custom form to select a date: replacement of datepicker), and after selecting the date, and on the click on the button "OK" the selected date value should go to the textbox "TextBox1" in the form "GenerateRequest", and should hide the form "DatePickerForm".

Problem:

When I select a date the selected date is filled in the textbox, but when I click on the button to select a date the previous selected date show's in the text box, like when the first time I click on the button to select a date, I select the date "3/2/2019" and after clicking on the button "OK" nothing happens, when again I click on the button to sect the form after the pervious date "3/2/2019" appears in the textbox, now when I select another date "4/5/2019" and click on "OK" button, the date not changed in the textbox1, now again as soon as click on the button to open the form to select the date the previous date "4/5/2019" appears in the textbox1.

I don't no what is the problem please help me.

Note:- I have public variable "datevalue" to hold the date

Button "cmddate" Click Event Code

Code:
Private Sub cmddate_Click()
    DatePickerForm.lblControl = "TextBox1"
    DatePickerForm.lblForm = Me.Name
    DatePickerForm.Show vbModeless
    DoEvents
    Me.TextBox1.Value = datevalue
End Sub

Button "OK" Click Event Code

Code:
Private Sub ShowDate_Click()


    'MsgBox Calendar1.Value
    'Dim myform As Object
    'Set myform = VBA.UserForms.Add(Me.lblForm.Caption)


    'myform.Controls(Me.lblControl.Caption).Value = Controldd.Value
    'DoEvents
    datevalue = Controldd.Value
    Me.Hide
End Sub


Thanks
Kashif
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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