If I have a textbox 1 which will be a date entry I need to add 18 years to the date and show new date in textbox 2
this is on a user pop up form so need it in VBA
EG 01/10/2000 + 18yr = 01/10/2018
text 1 text 2
If I have a textbox 1 which will be a date entry I need to add 18 years to the date and show new date in textbox 2
this is on a user pop up form so need it in VBA
EG 01/10/2000 + 18yr = 01/10/2018
text 1 text 2
Hi mmikem
Try
Please Login or Register to view this content.
Click *Add Reputation to thank those who helped you. Ask if anything is not clear
Hi Kev Thanks for the help but I get a error 13 when I run it txtDob is text box 1 and txtLyy is text box 2 mm/dd/yyyy I think it is the date formatting screw it up
[Private Sub txtDob_Change()
x = txtDob.Value
txtLyy.Value = DateSerial(Year(x) + 18, Month(1), Day(1))
End Sub
Private Sub txtLyy_Change()
End Sub ]
Any chance you could upload a sample workbook?
Click on GO ADVANCED, scroll down and click Manage Attachments.
If posting code please use code tags, see here.
I have tried clicked on paper clip but can not do anything will not let me attach file
Her you go got it to work there is other code that I am working on
Last edited by mmikem; 02-22-2018 at 05:03 PM. Reason: replace file
Does this work?
Please Login or Register to view this content.
Like this?
Please Login or Register to view this content.
This illustrates DATESERIAL, YEAR, MONTH, DAY functions:Hi Kev Thanks for the help but I get a error 13 when I run it txtDob is text box 1 and txtLyy is text box 2 mm/dd/yyyy I think it is the date formatting screw it up
x = txtDob.Value
txtLyy.Value = DateSerial(Year(x) + 18, Month(1), Day(1))
so perhaps:Please Login or Register to view this content.
this should also work:Please Login or Register to view this content.
Please Login or Register to view this content.
Last edited by kev_; 02-22-2018 at 02:09 AM.
I am unable to show your userform - VBA tells me it is looking for missing references
So you must help me
Put the code below in your userform
- then open your form
- use 25 December 2000 as your DOB (input it as you normally would)
- what does each message box return?
(some may return nothing)
On Error Resume Next
MsgBox "1 " & txtDob.Value
MsgBox "2 " & CDate(txtDob.Value)
MsgBox "3 " & Val(txtDob.Value)
MsgBox "4 " & CStr(txtDob.Value)
MsgBox "5 " & CInt(txtDob.Value)
MsgBox "6 " & Int(CDbl(txtDob.Value))
MsgBox "7 " & Format(txtDob.Value, "DD MMM YYYY")
thanks
This is the reason why nothing is working - you have broken your textbox! Or else the data you are inputting is being treated as invalid.Originally Posted by mmikem
The final message box returns 1 January 1900. In case you are not aware, 1 January 1900 is the first date that Excel recognises. So, somehow your textbox is returning the value 1 (driven by the error no doubt)
So that we are on exactly the same page, please attach your latest workbook to the thread. I will look at your textbox properties etc tomorrow.
Q1 How are you wanting to input values into your textbox? How would you input 25 December 2007?
Q2 As a matter of interest, when did the textbox start displaying thus error ?
(I am guessing it was before you started this thread because there is nothing in this thread altering that textbox in any way.)
Q3 It may be your click event that is triggering the error. When did you introduce that?
(This could be the source of mismatch error possibly)
Here is latest file
Last edited by mmikem; 02-23-2018 at 10:34 AM.
mmikem
Are you using a 'non-standard' control, e.g DTPicker?
I think I understand the cause of your error
- I have tested what I am suggesting below on your form and it functioned as expected.
Step1 Delete Private Sub txtDob_Change
- it is clashing with the input of date of birth
- this is why you are getting your error
Step 2 Replace it with this sub
Step 3 TestPlease Login or Register to view this content.
- run your form
- enter date in DOB field
- click inside Last Year Of Youth
As an alternative you could try updating LastYearOfYouth when you exit DOB
- try this after you have tested the above
Please Login or Register to view this content.
Last edited by kev_; 02-23-2018 at 05:38 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks