We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide
MS Access, Calculated Date Field
Benjo_2
Posts: 69 Forumite
in Techie Stuff
Hi All
This may be to specialized for this forum but I was hoping that someone may be able to help or even point me in the right direction of a forum that would be able to assist
I am developing an application in Access that is using calculated date fields. I have placed the code below in the "control Source" of a control
=IIf(IsNull([StartDate]),DateSerial(Year([Text26])+[Text21],Month([Text26]),Day([Text26])),DateSerial(Year([StartDate])+[Text21],Month([StartDate]),Day([StartDate])))
The code in itself works fine, however, if for any reason, [Text26] or [Text21] are Null I get a response displaying #ERROR. I would like it just to remain blank.
I cant for the life of me figure out how to get around this in this piece of code,
Hope someone can point me in the right direction
Ben
This may be to specialized for this forum but I was hoping that someone may be able to help or even point me in the right direction of a forum that would be able to assist
I am developing an application in Access that is using calculated date fields. I have placed the code below in the "control Source" of a control
=IIf(IsNull([StartDate]),DateSerial(Year([Text26])+[Text21],Month([Text26]),Day([Text26])),DateSerial(Year([StartDate])+[Text21],Month([StartDate]),Day([StartDate])))
The code in itself works fine, however, if for any reason, [Text26] or [Text21] are Null I get a response displaying #ERROR. I would like it just to remain blank.
I cant for the life of me figure out how to get around this in this piece of code,
Hope someone can point me in the right direction
Ben
0
Comments
-
Hmm....It has been a while since I have done any Access programming so I am not entirely sure what I am talking about, however surely if you are trying to work out Year, Month or Day from a NULL field you are going to get an error. 0 is not a valid date in any format and so you cannot work out a year from it. You may need another IF statement saying that if the 26 or 21 are Null then leave the date empty.0
-
Hi there
That is the problem. I have another calculated field (see below) which rightly sets the value to "" if a control is blank, but i do not know how to incorportate it in the statement above.
=IIf(IsNull([Text26]),"",DateSerial(Year([Text26])+[Text15],Month([Text26])+[TermM],Day([Text26]+[TermD])))0 -
Can you not do a nested if statement?
So basically:
=IIf(IsNull([StartDate]),IIf(IsNull([Text26]),"",DateSerial(Year([Text26])+[Text15],Month([Text26])+[TermM],Day([Text26]+[TermD])))), DateSerial(Year([StartDate])+[Text21],Month([StartDate]),Day([StartDate])))0 -
No I tried it and got a message saying,
"The expression you entered contains invalid syntax, or you need to enclose your text data in quotes"
Any other ideas?0 -
Erm....unfortunately no
I'm all out of ideas 0 -
Cheers for a good effort anyway
anyone else?0 -
Put some ifs at the beginning to make it blank if either Text21 or 26 are blank.
=IIf(IsNull([text21]),"",IIf(IsNull([text26]),"",IIf(IsNull([StartDate]),DateSerial(Year([Text26])+[Text21],Month([Text26]),Day([Text26])),DateSerial(Year([StartDate])+[Text21],Month([StartDate]),Day([StartDate])))))
Remember to add the brackets at the end.0 -
=Iif(IsNull([StartDate]) and [Text26]>0 and [Text21]>0,DateSerial(Year([Text26])+[Text21],Month([Text26]),Day([Text26])),Iif([Text21]>0,DateSerial(Year([StartDate])+[Text21],Month([StartDate]),Day([StartDate])),Null))
seems to work here for me
Cheers
Al0 -
PhilCo that worked a treat thanks so much.
I cant believe it was really that easy, I have been looking at that for hours
Thank you eveybody for all your help.
Ben0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 353.5K Banking & Borrowing
- 254.1K Reduce Debt & Boost Income
- 455K Spending & Discounts
- 246.6K Work, Benefits & Business
- 602.9K Mortgages, Homes & Bills
- 178.1K Life & Family
- 260.6K Travel & Transport
- 1.5M Hobbies & Leisure
- 16K Discuss & Feedback
- 37.7K Read-Only Boards