problem function date add into datepicker on userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi
i have problem add years and months days is ok i have textbox1= days textbox2= months textbox3= years when i choose in datepicker1= date then add months an years to datepicker2
this is my simple code
VBA Code:
Private Sub CommandButton2_Click()
    datepicker2 = DateAdd("d", textbox1.Text, datepicker1)
     datepicker2 = DateAdd("M", textbox2.Text, datepicker1)
      datepicker2 = DateAdd("YYYY", textbox3.Text, datepicker1)
End Sub


1.JPG
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
yes that what i ment dante but it gives me error mismatch 13
Do you have variables?
How do you have those variables declared?
datepicker2 is a variable or is it a Textbox?

Put your complete code here and tell us which is variable and which is a textbox.
 
Upvote 0
i don't declare variables and datepicker2 this tool from the addition tool called "datepicker and time" not textbox as you see my image
 
Upvote 0
You can put all your code here.

With an image we cannot determine if it is a combo or dtpicker or something else, could you help us help you.
If we ask you Rick and I, it is because your explanation is not clear.
 
Upvote 0
Try this

VBA Code:
Private Sub CommandButton2_Click()
  If Not IsNumeric(TextBox1.Value) Then
    MsgBox "Textbox1 is not number"
    Exit Sub
  End If
  If Not IsNumeric(TextBox2.Value) Then
    MsgBox "Textbox2 is not number"
    Exit Sub
  End If
  If Not IsNumeric(TextBox3.Value) Then
    MsgBox "Textbox3 is not number"
    Exit Sub
  End If
  datepicker2 = DateAdd("d", TextBox1.Value, datepicker1)
  datepicker2 = DateAdd("M", TextBox2.Value, datepicker2)
  datepicker2 = DateAdd("YYYY", TextBox3.Value, datepicker2)
End Sub

If you have problems, you can put your complete code here. On which line you have the problem, the error message and what data you have in each of your textbox and Dtpicker1.
 
Upvote 0
userform contains
1- (5 ) textbox
2- (2) ditpicker
as the image write first date in textbox1 ,textbox2= end date then press account it gives me textbox3= days , textbox4= months ,textbox5= years then when i choose date from dtpicker1 an press add and it adds value in textbox3,4,5 to dtpicker2
 
Upvote 0
Now I do not understand.
This is your original code.

VBA Code:
Private Sub CommandButton2_Click()
    datepicker2 = DateAdd("d", textbox1.Text, datepicker1)
     datepicker2 = DateAdd("M", textbox2.Text, datepicker1)
      datepicker2 = DateAdd("YYYY", textbox3.Text, datepicker1)
End Sub

Now you mention textbox3,4 and 5

Then put here your complete code of all your userform
and the content that each textbox has at the time of execution.
And by content, I mean, if at the time of execution in textbox1 you have 17, then here you say content of textbox1 = 17.
and so for each textbox.
 
Upvote 0
1590377918375.png


We will not move forward if you rename the controls.
Now the texbox for days what is it? the textbox3, the 4 or the 5?
 
Upvote 0
Try this

Adjust the name textbox3, 4 and 5 according to your textbox.

VBA Code:
Private Sub CommandButton2_Click()
  'DAYS
  If Not IsNumeric(TextBox3.Value) Then
    MsgBox "Textbox3 is not number"
    Exit Sub
  End If
  'MONTHS
  If Not IsNumeric(TextBox4.Value) Then
    MsgBox "Textbox4 is not number"
    Exit Sub
  End If
  'YEARS
  If Not IsNumeric(TextBox5.Value) Then
    MsgBox "Textbox5 is not number"
    Exit Sub
  End If
  'DAYS
  datepicker2 = DateAdd("d", TextBox3.Value, datepicker1)
  'MONTHS
  datepicker2 = DateAdd("M", TextBox4.Value, datepicker2)
  'YEARS
  datepicker2 = DateAdd("YYYY", TextBox5.Value, datepicker2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

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