Calculating Date Problem

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
I have 2 text boxes. Text1 and Text2
both are formated as short date.
In text1 a date is keyed in i.e. 12/02/04 (Dec 2/04)
I want text2 to show the date 6months from the date entered in Text1.

In text2 I am entering the Date worksheet funtion.

=Date(Year(text1),Month(text1)+6,Day(text1) I also tried
=Date(Year([text1]),Month([text1])+6,Day([text1])

In both cases I receive the error message "function contains the wrong number of arguments"

Is does this fuction not work in access ( It works for me in excel)? If this is the case, how can I get this calculation to work in access?

Thanks
Liz
Code:
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Access doesn't recognize the date() function like your thinking, that's a worksheet function only. The reason you get the wrong number of arguments is because Access will return the current date when the date() is used with no arguments (like now()).

Try:
IIf(Month([date])>6,CDate(Month([date])-6 & "/" & Day([date]) & "/" & Year([date])+1),CDate(Month([date])+6 & "/" & Day([date]) & "/" & Year([date])))

Replace [date] with your control name, it looks like text1.
 
Upvote 0
Hi Liz,

An alternative method to that proposed by Corticus is to replace your formula with this :

=DateAdd("m", 6, [text1])

HTH, Andrew. :)
 
Upvote 0
Thank you both very much.

the =DateAdd("m", 6, [text1])

worked Beautifully
Liz
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,250
Members
451,757
Latest member
iours

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