VBA Form Autofill

nanofied

New Member
Joined
Aug 28, 2018
Messages
18
Hi guys, I have a form with many text boxes. The 2 text boxes for importance in my query is "Date of Commencement" and "Estimated Date of Completion". The "Estimated Date of Completion" is to be 120 days after the "Date of Commencement". By using the code:
Code:
EstimatedDateofCompletion.Value =  DateAdd("d", 120, DateofCommencement.Value
I wish to autofill "Estimated Date of Completion" text box. however I have been receiving a type mismatch error. How many I solve this issue. or code it in a better way
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this:
EstimatedDateofCompletion = DateAdd("d", 120, CDate(DateofCommencement))
 
Upvote 0
Thanks! I have another question. In my form after I had type in the DateofCommencement textbox, the value in EstimatedDateofCompletion does not refresh automatically. The value will only be inputted if I make a change to the the form. Is there anyway to for the value to be inputted immediately and automatically without making a change
 
Upvote 0
Put this script in your userform
Code:
Private Sub DateofCommencement_Exit(ByVal Cancel As MSForms.ReturnBoolean)
EstimatedDateofCompletion = DateAdd("d", 120, CDate(DateofCommencement))
End Sub

You enter the date you want in the
DateofCommencement

Textbox then when you press tab or some how exit the textbox the script will run.

 
Upvote 0
Now that we have you what you want.
Use this script:

This script will warn you and stop the script if a improper value is entered which is not a date.

Code:
Private Sub DateofCommencement_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Modified  11/12/2018  4:10:23 AM  EST
On Error GoTo M
EstimatedDateofCompletion = DateAdd("d", 120, CDate(DateofCommencement))
Exit Sub
M:
MsgBox "The value you entered is not a proper date"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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