Error when trying to save a query

T

Tara

I posted a question earlier today about Access shutting down when I tried to
open a specific query in design view. It seems there is another issue with
this query too. I rebuilt the query again and now I can see it in design
view, but when I try to save it, I get the following message: Missing ), ],
or Item in query expression IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/’.

Obviously Access cut the expression short in it's message, so below is the
entire expression.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED,
IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)+Int((Date()-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]=0,Int(([TerminationDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]>0,Int(([TerminationDate]-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks)+Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)))))
AS ytd,
IIf([curContribADJUSTED]=0,([curContrib]/tblWeeks!Weeks),IIf([curContribADJUSTED]>0,([curContribADJUSTED]/tblWeeks!Weeks),IIf([curCo
ntribADJUSTED]>0 And ([ytd]>[curContribADJUSTED]),0))) AS
[BiWeeklyWitholding], tblWeeks.Weeks, IIf([curContribADJUSTED]>0 And
([ytd]>[curContribADJUSTED]),0,[BiWeeklyWitholding]) AS [BiWeeklyWitholding2]
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);


If anyone can point out where the issue is, I'd really appreciate it.

Thanks!
 
J

Jerry Whittle

This part looks strange. It looks like the two tables are joined twice. Maybe
I'm just not reading it properly.

INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

Try a simpler query like below. If it works, then the problem is probably in
the very complex SELECT area.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

If the simple query above didn't work, try this one which gets away from the
double join above.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM tblEmployee, tbl125, tblWeeks
WHERE tblEmployee.numIdNum=tbl125.numIDNum
AND tblEmployee.numIdNum=tblWeeks.numIDNum
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tara said:
I posted a question earlier today about Access shutting down when I tried to
open a specific query in design view. It seems there is another issue with
this query too. I rebuilt the query again and now I can see it in design
view, but when I try to save it, I get the following message: Missing ), ],
or Item in query expression IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/’.

Obviously Access cut the expression short in it's message, so below is the
entire expression.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED,
IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)+Int((Date()-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]=0,Int(([TerminationDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]>0,Int(([TerminationDate]-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks)+Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)))))
AS ytd,
IIf([curContribADJUSTED]=0,([curContrib]/tblWeeks!Weeks),IIf([curContribADJUSTED]>0,([curContribADJUSTED]/tblWeeks!Weeks),IIf([curCo
ntribADJUSTED]>0 And ([ytd]>[curContribADJUSTED]),0))) AS
[BiWeeklyWitholding], tblWeeks.Weeks, IIf([curContribADJUSTED]>0 And
([ytd]>[curContribADJUSTED]),0,[BiWeeklyWitholding]) AS [BiWeeklyWitholding2]
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);


If anyone can point out where the issue is, I'd really appreciate it.

Thanks!
 
T

Tara

Thanks for the reply Jerry. The simpler query you gave works fine. I
realize the query is complex, and I know there must be a better way of
approaching this, but I'm not sure what it is. Could you give me some ideas
on how to make the query less complicated?

Thanks again

Jerry Whittle said:
This part looks strange. It looks like the two tables are joined twice. Maybe
I'm just not reading it properly.

INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

Try a simpler query like below. If it works, then the problem is probably in
the very complex SELECT area.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

If the simple query above didn't work, try this one which gets away from the
double join above.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM tblEmployee, tbl125, tblWeeks
WHERE tblEmployee.numIdNum=tbl125.numIDNum
AND tblEmployee.numIdNum=tblWeeks.numIDNum
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tara said:
I posted a question earlier today about Access shutting down when I tried to
open a specific query in design view. It seems there is another issue with
this query too. I rebuilt the query again and now I can see it in design
view, but when I try to save it, I get the following message: Missing ), ],
or Item in query expression IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/’.

Obviously Access cut the expression short in it's message, so below is the
entire expression.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED,
IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)+Int((Date()-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]=0,Int(([TerminationDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]>0,Int(([TerminationDate]-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks)+Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)))))
AS ytd,
IIf([curContribADJUSTED]=0,([curContrib]/tblWeeks!Weeks),IIf([curContribADJUSTED]>0,([curContribADJUSTED]/tblWeeks!Weeks),IIf([curCo
ntribADJUSTED]>0 And ([ytd]>[curContribADJUSTED]),0))) AS
[BiWeeklyWitholding], tblWeeks.Weeks, IIf([curContribADJUSTED]>0 And
([ytd]>[curContribADJUSTED]),0,[BiWeeklyWitholding]) AS [BiWeeklyWitholding2]
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);


If anyone can point out where the issue is, I'd really appreciate it.

Thanks!
 
J

Jerry Whittle

When there are that many IIf statements, it's often a case that the basic
table structure is wrong. The fix would entail rebuilding the database - not
a job taken lightly.

Another option would be to use a Case statement in a function instead of
IIf. It often works much more efficiently plus is easier to trap errors. It
would look something like below. You would wrap the fTiers around the fields.
However you have multiple OR clauses which would make the logic very
difficult to figure out.

Function fTiers(strTiers As Variant) As String
Dim TheTier As String
Select Case strTiers
Case Is > -10000 ' greater than -10000
TheTier = "Tier1"
Case -1000000 To -10000
TheTier = "Tier2"
Case Is < -1000000 ' Number less than -1000000
TheTier = "Tier4"
Case Else ' Other values.
TheTier = "Not Tier"
End Select
fTiers = TheTier
End Function

Yet another option is to make a simpler query, for example just doing part
of the calculation say on the Nulls, then using this query as the record
source for another query that finishes the job.

The last thing that I can think of is to create a table of appropriate
values and join this table. Easy for me to say; difficult to do in practice.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Tara said:
Thanks for the reply Jerry. The simpler query you gave works fine. I
realize the query is complex, and I know there must be a better way of
approaching this, but I'm not sure what it is. Could you give me some ideas
on how to make the query less complicated?

Thanks again

Jerry Whittle said:
This part looks strange. It looks like the two tables are joined twice. Maybe
I'm just not reading it properly.

INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

Try a simpler query like below. If it works, then the problem is probably in
the very complex SELECT area.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

If the simple query above didn't work, try this one which gets away from the
double join above.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM tblEmployee, tbl125, tblWeeks
WHERE tblEmployee.numIdNum=tbl125.numIDNum
AND tblEmployee.numIdNum=tblWeeks.numIDNum
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

Tara said:
I posted a question earlier today about Access shutting down when I tried to
open a specific query in design view. It seems there is another issue with
this query too. I rebuilt the query again and now I can see it in design
view, but when I try to save it, I get the following message: Missing ), ],
or Item in query expression IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/’.

Obviously Access cut the expression short in it's message, so below is the
entire expression.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED,
IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)+Int((Date()-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]=0,Int(([TerminationDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]>0,Int(([TerminationDate]-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks)+Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)))))
AS ytd,
IIf([curContribADJUSTED]=0,([curContrib]/tblWeeks!Weeks),IIf([curContribADJUSTED]>0,([curContribADJUSTED]/tblWeeks!Weeks),IIf([curCo
ntribADJUSTED]>0 And ([ytd]>[curContribADJUSTED]),0))) AS
[BiWeeklyWitholding], tblWeeks.Weeks, IIf([curContribADJUSTED]>0 And
([ytd]>[curContribADJUSTED]),0,[BiWeeklyWitholding]) AS [BiWeeklyWitholding2]
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);


If anyone can point out where the issue is, I'd really appreciate it.

Thanks!
 
T

Tara

Thanks so much for the advice Jerry. I really appreciate it.

I'm confident that the table structure is correct. The issue is that there
are many variable conditions that can affect the calculations.
Unfortunately, that requires complex queries, at least for me it does, since
I'm new to coding. I think I'll try your third solution. It sounds like the
best/easiest fix for now.

Jerry Whittle said:
When there are that many IIf statements, it's often a case that the basic
table structure is wrong. The fix would entail rebuilding the database - not
a job taken lightly.

Another option would be to use a Case statement in a function instead of
IIf. It often works much more efficiently plus is easier to trap errors. It
would look something like below. You would wrap the fTiers around the fields.
However you have multiple OR clauses which would make the logic very
difficult to figure out.

Function fTiers(strTiers As Variant) As String
Dim TheTier As String
Select Case strTiers
Case Is > -10000 ' greater than -10000
TheTier = "Tier1"
Case -1000000 To -10000
TheTier = "Tier2"
Case Is < -1000000 ' Number less than -1000000
TheTier = "Tier4"
Case Else ' Other values.
TheTier = "Not Tier"
End Select
fTiers = TheTier
End Function

Yet another option is to make a simpler query, for example just doing part
of the calculation say on the Nulls, then using this query as the record
source for another query that finishes the job.

The last thing that I can think of is to create a table of appropriate
values and join this table. Easy for me to say; difficult to do in practice.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Tara said:
Thanks for the reply Jerry. The simpler query you gave works fine. I
realize the query is complex, and I know there must be a better way of
approaching this, but I'm not sure what it is. Could you give me some ideas
on how to make the query less complicated?

Thanks again

Jerry Whittle said:
This part looks strange. It looks like the two tables are joined twice. Maybe
I'm just not reading it properly.

INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

Try a simpler query like below. If it works, then the problem is probably in
the very complex SELECT area.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);

If the simple query above didn't work, try this one which gets away from the
double join above.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED
FROM tblEmployee, tbl125, tblWeeks
WHERE tblEmployee.numIdNum=tbl125.numIDNum
AND tblEmployee.numIdNum=tblWeeks.numIDNum
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

:

I posted a question earlier today about Access shutting down when I tried to
open a specific query in design view. It seems there is another issue with
this query too. I rebuilt the query again and now I can see it in design
view, but when I try to save it, I get the following message: Missing ), ],
or Item in query expression IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/’.

Obviously Access cut the expression short in it's message, so below is the
entire expression.

SELECT tbl125.numIDNum, tbl125.dtmPlanStart, tbl125.strPlanType,
tbl125.ADJUSTEDStartDate, tbl125.curContrib, tbl125.curContribADJUSTED,
IIf([TerminationDate] Is Null And
[curContribADJUSTED]=0,Int((Date()-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Null And
[curContribADJUSTED]>0,Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)+Int((Date()-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]=0,Int(([TerminationDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks),IIf([TerminationDate]
Is Not Null And
[curContribADJUSTED]>0,Int(([TerminationDate]-tbl125!ADJUSTEDStartDate)/14)*(tbl125!curContribADJUSTED/tblWeeks!Weeks)+Int(([ADJUSTEDStartDate]-tbl125!dtmPlanStart)/14)*(tbl125!curContrib/tblWeeks!Weeks)))))
AS ytd,
IIf([curContribADJUSTED]=0,([curContrib]/tblWeeks!Weeks),IIf([curContribADJUSTED]>0,([curContribADJUSTED]/tblWeeks!Weeks),IIf([curCo
ntribADJUSTED]>0 And ([ytd]>[curContribADJUSTED]),0))) AS
[BiWeeklyWitholding], tblWeeks.Weeks, IIf([curContribADJUSTED]>0 And
([ytd]>[curContribADJUSTED]),0,[BiWeeklyWitholding]) AS [BiWeeklyWitholding2]
FROM (tblEmployee INNER JOIN tbl125 ON tblEmployee.numIdNum=tbl125.numIDNum)
INNER JOIN tblWeeks ON (tblEmployee.numIdNum=tblWeeks.numIDNum) AND
(tblEmployee.numIdNum=tblWeeks.numIDNum);


If anyone can point out where the issue is, I'd really appreciate it.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top