This is just the type of formula that you need to "step through". It is a
nested IIF. This means that forumlas are "nested" (placed) inside other
formulas.
If I was you I would "step through" each section of the formula one by one.
I may be wrong (I learnd english at school) but I "think" step through means
to test each bit of the formual or code to see where it fails - or it may not
fail.
So
Create the most basic (normally the 1st in a nested IIF) section of the
formula and see if it works. If it does add the next bit and so on.
Another benifi of this is that you will learn "how" the forumula works
rather than just copying it. This is "vital" as it means you can change it
if needed.
I have spotted where you are going wrong - but, this is the 1st time I have
said this in the forum - I am not going to tell you the answer. You must
step though and test it yourself. You "will" find it. It is very simple
error.
Try this
IIF formulas "only" give True or False. If something is True "display"
something, if it is False either Display something else or do another formula.
You want to arrive at an answer that that is "true".
You need to check "each" forula at a time.
This is you formula and it complex - so cut it down
Weekdays are Sun=1 Mon=2 Tues=3 etc etc
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7),IIf(Weekday([Received])=6
And [Time Rec]>#12:01:00#,([Received]-Weekday([received],3)+7),IIf([Time
Rec]>#12:01:00#,[received],DateAdd("d",1,[received],
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7),IIf(Weekday([Received])=7
And [Time Rec]>#12:01:00#,([Received]-Weekday([received],3)+7),IIf([Time
Rec]<#12:01:00#,[received],DateAdd("d",1,[received]))))
The 1st part of the formula is this
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7)
What is this doing???
You are asking a question - the first part is this.....
If this statment is true - - - the content of the field named [received]
has a "weekday" number that = 7 or a weekeday number = 1 then you want to
display the following Monday.
You get the follwing Monday date using the formula
([received]-Weekday([Received],3)+7)
If the statment is NOT true (false) you want to ask
Ok then if that statment is Not true then lets check if somethign else is
true. So you say - right then the 1st statment is false what about this
IIf(Weekday([Received])=6 > And [Time
Rec]>#12:01:00#,([Received]-Weekday([received],3)+7)
As you will see - this is the 2nd part of your (big) formula
So this is False (the content of your field [recieved] is NOT = 7 (Saturday)
or = 1 (Sunday)
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7)
So you ask the next question
OK if it's not either Saturday or Sunday then what this
IIf(Weekday([Received])=6 > And [Time
Rec]>#12:01:00#,([Received]-Weekday([received],3)+7)
If the content of the field [receive] = 6 (Friday) AND the content of the
field [Time Rec] > (is greater than) #12:01:00# (1 minute after 12 noon) then
again - using the same section of the formula as above
([Received]-Weekday([received],3)+7) display the date of the following Monday.
If this statment is also not true you need to ask another question
IIf([Time Rec]>#12:01:00#,[received],DateAdd("d",1,[received]
If the content of [Time Rec] is greater than 12:01:00 then insert then
content of [recieved] if not then add one day to the date contained within
the field [received] - which is what this section does - - -
DateAdd("d",1,[received].
Ask you can see if you break it down you "Will" find the answer.
If this is your 1st nested if then you may want to read up on the subject
before you start. This formla "looks" complex but if you break it down in to
it individual section it is really very simple. Is this true then do this,
if not then do something else or ask another question, if the 2nd question is
true then do this or (again) ask another question.
Just one point. If you are making am application for a company it is "your"
task to understand what you are doing. It "will" go wrong sooner or later
and you company (boss, workmates, etc) will look to you to fix it. It is
really not a good idea just to copy codes that seem to work and use them.
You "really do need" to understand them.
Good luck
I hope this helped a littl.
--
Wayne
Manchester, England.
ASSK said:
I have created a test database where the LLOOReqDate is the same as
[Received] and LLOOReqTime is the same as [Time Rec]. I have combined the
function you've written for me together and this is what it looks like.
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7),IIf(Weekday([Received])=6
And [Time Rec]>#12:01:00#,([Received]-Weekday([received],3)+7),IIf([Time
Rec]>#12:01:00#,[received],DateAdd("d",1,[received],
IIf(Weekday([received])=7 Or
Weekday([received])=1,([received]-Weekday([Received],3)+7),IIf(Weekday([Received])=7
And [Time Rec]>#12:01:00#,([Received]-Weekday([received],3)+7),IIf([Time
Rec]<#12:01:00#,[received],DateAdd("d",1,[received]))))
What wrong with this? It's telling me "The expression you entered has a
function containing the wrong number of arguments".
Please tell me what I am doing wrong.....
Wayne-I-M said:
opps - sorry (forgot to add the Friday after 12pm exclusion)
Expected Completion Date: IIf(Weekday([TableName]![LLOOReqDate])=7 Or
Weekday([TableName]![LLOOReqDate])=1,([TableName]![LLOOReqDate]-Weekday([TableName]![LLOOReqDate],3)+7),IIf(Weekday([TableName]![LLOOReqDate])=6
And
[TableName]![LLOOReqTime]>#12:01:00#,([TableName]![LLOOReqDate]-Weekday([TableName]![LLOOReqDate],3)+7),IIf([TableName]![LLOOReqTime]<#12:01:00#,[TableName]![LLOOReqDate],DateAdd("d",1,[TableName]![LLOOReqDate]))))
--
Wayne
Manchester, England.
ASSK said:
Hi,
I have a a function below in my query, where it either add 1 or two day/s to
the LLOOReqDate depending on when I receieve the request. The problem is if I
receive the requeston a Friday, then it will need to show that the expected
completion date should either be the next business day (i.e. Monday (1) or
the following Business day (i.e. Tuesday (2)).
Expected Completion Date: DateAdd("d",IIf([LLOOReqTime]<=#12:00:00
PM#,1,2),[LLOOReqDate])
Pls tell me how to do this. I am new at this and don't know anything about
VBA or coding.