Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Getting r/t error

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,344
Default Getting r/t error

Hi,

Your textbox returns text and the DateDif function needs a legal date try
using CDate
Look it up in the VBA help.

CDate(TextBox19.Text)

Also, I don't see any reason to apply the Format command, if the user does
not enter the data in a legal date format this code is not going to help.

If this helps, please click the Yes button.
--
Thanks,
Shane Devenshire


"JMay" wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Getting r/t error

Thanks Shane,
But where do I put the statement
CDate(TextBox19.Text)
and what do i eliminate from what I now have?

"ShaneDevenshire" wrote:

Hi,

Your textbox returns text and the DateDif function needs a legal date try
using CDate
Look it up in the VBA help.

CDate(TextBox19.Text)

Also, I don't see any reason to apply the Format command, if the user does
not enter the data in a legal date format this code is not going to help.

If this helps, please click the Yes button.
--
Thanks,
Shane Devenshire


"JMay" wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting r/t error

Private Sub TextBox19_AfterUpdate()
if isdate(me.textbox19.text) then
me.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(me.TextBox19.Text), "mm/dd/yyyy"), Date, "y")
end if
End Sub

(Untested, uncompiled!)


JMay wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Getting r/t error

Thanks Dave (as usual) -- I tried your code, but didn't work. I've since
modified to:

Private Sub TextBox19_AfterUpdate()
MyBDate = CDate(TextBox19)
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate,
Date, "y")
End Sub

But still getting r/t error 438 - Object doesn't support this prop or meth
On line
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate, Date,
"y")



What to do (wringing hands here)...


"Dave Peterson" wrote:

Private Sub TextBox19_AfterUpdate()
if isdate(me.textbox19.text) then
me.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(me.TextBox19.Text), "mm/dd/yyyy"), Date, "y")
end if
End Sub

(Untested, uncompiled!)


JMay wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 468
Default Getting r/t error

STOP THE PRESSES !!!

Googling enough - I've determined that my problem is likely the DATEDIF (one
"F")
is not supported in VBA (in conjunction with Worksheetfunction..) There is
however a DATEDIFF (2 "F's") Soooooo

Private Sub TextBox19_AfterUpdate()
MyBDate = CDate(TextBox19)
If DateSerial(Year(Date), Month(MyBDate), Day(MyBDate)) <= Date Then
Me.TextBox20 = Abs(DateDiff("yyyy", Date, MyBDate))
Else
Me.TextBox20 = Abs(DateDiff("yyyy", Date, MyBDate) + 1)
End If
End Sub

THIS IS WORKING GREAT !!!

"JMay" wrote:

Thanks Dave (as usual) -- I tried your code, but didn't work. I've since
modified to:

Private Sub TextBox19_AfterUpdate()
MyBDate = CDate(TextBox19)
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate,
Date, "y")
End Sub

But still getting r/t error 438 - Object doesn't support this prop or meth
On line
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate, Date,
"y")



What to do (wringing hands here)...


"Dave Peterson" wrote:

Private Sub TextBox19_AfterUpdate()
if isdate(me.textbox19.text) then
me.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(me.TextBox19.Text), "mm/dd/yyyy"), Date, "y")
end if
End Sub

(Untested, uncompiled!)


JMay wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting r/t error

I didn't test the guts of your code--just the part that needed to check for a
date.

You still may want to check to see if you're working with a date with IsDate()
and if you really wanted to use the worksheet function (=datedif()), remember
you can use application.evaluate().

JMay wrote:

STOP THE PRESSES !!!

Googling enough - I've determined that my problem is likely the DATEDIF (one
"F")
is not supported in VBA (in conjunction with Worksheetfunction..) There is
however a DATEDIFF (2 "F's") Soooooo

Private Sub TextBox19_AfterUpdate()
MyBDate = CDate(TextBox19)
If DateSerial(Year(Date), Month(MyBDate), Day(MyBDate)) <= Date Then
Me.TextBox20 = Abs(DateDiff("yyyy", Date, MyBDate))
Else
Me.TextBox20 = Abs(DateDiff("yyyy", Date, MyBDate) + 1)
End If
End Sub

THIS IS WORKING GREAT !!!

"JMay" wrote:

Thanks Dave (as usual) -- I tried your code, but didn't work. I've since
modified to:

Private Sub TextBox19_AfterUpdate()
MyBDate = CDate(TextBox19)
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate,
Date, "y")
End Sub

But still getting r/t error 438 - Object doesn't support this prop or meth
On line
UserForm1.TextBox20 = Application.WorksheetFunction.DateDif(MyBDate, Date,
"y")



What to do (wringing hands here)...


"Dave Peterson" wrote:

Private Sub TextBox19_AfterUpdate()
if isdate(me.textbox19.text) then
me.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(me.TextBox19.Text), "mm/dd/yyyy"), Date, "y")
end if
End Sub

(Untested, uncompiled!)


JMay wrote:

After entering say 11/27/44 in my TextBox 19 I want Textbox20 to display 63,
but it is not working

Anyone see why?

Private Sub TextBox19_AfterUpdate()
UserForm1.TextBox20.Text = Application.WorksheetFunction. _
DateDif(Format(DateValue(TextBox19.Text), "mm/dd/yyyy"), Date, "y")
End Sub

TIA,

--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"