dbTalk Databases Forums  

Parameter box showing when it shouldn't

comp.databases.ms-access comp.databases.ms-access


Discuss Parameter box showing when it shouldn't in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default Parameter box showing when it shouldn't - 11-20-2010 , 05:27 PM






Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questions]![QuestionID],[Questions]![QuestionID])))
GROUP BY Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending whether the form
is open.

If the form is open, all works as expected giving only the same question on
the form. If the form is closed, The parameter box comes up asking for a
value for Forms!Question!QuestionID, and regardless of what I put in there,
including just pressink the OK button, all the records in the query show as
they should ie 200 odd questions. Why is the "Enter Paramater Box" showing? -
more importantly, how do I stop it showing?

Thanks Phil

Reply With Quote
  #2  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-21-2010 , 08:09 AM






"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ic9lje$78d$1 (AT) speranza (DOT) aioe.org:

Quote:
Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending
whether the form is open.

If the form is open, all works as expected giving only the same
question on the form. If the form is closed, The parameter box
comes up asking for a value for Forms!Question!QuestionID, and
regardless of what I put in there, including just pressink the OK
button, all the records in the query show as they should ie 200
odd questions. Why is the "Enter Paramater Box" showing? - more
importantly, how do I stop it showing?

Thanks Phil

IIf() evaluates the 3 passed parameters, whether or not the first
parameter evaluates true or false.



--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-21-2010 , 12:21 PM



On 21/11/2010 14:09:10, Bob Quintal wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ic9lje$78d$1 (AT) speranza (DOT) aioe.org:

Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending
whether the form is open.

If the form is open, all works as expected giving only the same
question on the form. If the form is closed, The parameter box
comes up asking for a value for Forms!Question!QuestionID, and
regardless of what I put in there, including just pressink the OK
button, all the records in the query show as they should ie 200
odd questions. Why is the "Enter Paramater Box" showing? - more
importantly, how do I stop it showing?

Thanks Phil


IIf() evaluates the 3 passed parameters, whether or not the first
parameter evaluates true or false.



Thanks, Bob

Sorry, I must be a bit thick. What 3rd parameter. Only options are
[Forms]![Questions]![QuestionID] or [Questions]![QuestionID]

Phil

Reply With Quote
  #4  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-21-2010 , 01:02 PM



Bob Quintal wrote:

Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending
whether the form is open.

If the form is open, all works as expected giving only the same
question on the form. If the form is closed, The parameter box
comes up asking for a value for Forms!Question!QuestionID, and
regardless of what I put in there, including just pressink the OK
button, all the records in the query show as they should ie 200
odd questions. Why is the "Enter Paramater Box" showing? - more
importantly, how do I stop it showing?


IIf() evaluates the 3 passed parameters, whether or not the first
parameter evaluates true or false.

That's true for the VBA IIf function, but not for the
Expression Service IIf. A simple test could be something
like:
IIf(False, MsgBox("True"), MsgBox("False"))

Unfortunately, that does not help explain why Phil is being
prompted. Unlikely as it is, maybe it's because of the use
of ! instead of dot or all the useless parenthesis or
there's something funny in the IsLoaded function or ...??

--
Marsh

Reply With Quote
  #5  
Old   
Phil
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-21-2010 , 01:42 PM



On 21/11/2010 19:02:47, Marshall Barton wrote:
Quote:
SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;
Thanks Marsh

Is loaded has worked for years and is correctly giving 0

Have simplified even further to
SELECT Questions.Question, IsLoaded("Questions") AS Expr1
FROM Questions
WHERE
Questions.QuestionID=IIf(IsLoaded("Questions"),[Forms].[Questions].[QuestionID],[Questions].[QuestionID])

and get same result. Changing "!" to "." doesn't help either

Phil

Reply With Quote
  #6  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-21-2010 , 10:19 PM



Phil wrote:

Quote:
On 21/11/2010 19:02:47, Marshall Barton wrote:
SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

Thanks Marsh

Is loaded has worked for years and is correctly giving 0

Have simplified even further to
SELECT Questions.Question, IsLoaded("Questions") AS Expr1
FROM Questions
WHERE
Questions.QuestionID=IIf(IsLoaded("Questions"),[Forms].[Questions].[QuestionID],[Questions].[QuestionID])

and get same result. Changing "!" to "." doesn't help either

That should not work at all. You replaced one too many !

It should have been:

WHERE Questions.QuestionID = IIf(IsLoaded("Questions"),
Forms!Questions.QuestionID, Questions.QuestionID)

But I finally followed your example closely enough to
reproduce the behavior. After some head scratching and more
tests, I conclude that it the fact that
Forms!Questions.QuestionID is a query parameter and that the
prompt occurs before the query starts running. The IIf has
nothing to do with it.

I think you can work around it by not using a parameter and
calling a custom function in a standard module that returns
the ID from the form:

Public Function GetQID()
GetQID = Forms!Questions.QuestionID
End Function

and

WHERE Questions.QuestionID = IIf(IsLoaded("Questions"),
GetQID(), Questions.QuestionID)

--
Marsh

Reply With Quote
  #7  
Old   
Phil
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-22-2010 , 04:19 AM



On 22/11/2010 04:19:29, Marshall Barton wrote:
Quote:
Phil wrote:

On 21/11/2010 19:02:47, Marshall Barton wrote:
SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Questio
ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

Thanks Marsh

Is loaded has worked for years and is correctly giving 0

Have simplified even further to
SELECT Questions.Question, IsLoaded("Questions") AS Expr1
FROM Questions
WHERE
Questions.QuestionID=IIf(IsLoaded("Questions"),[Forms].[Questions].[QuestionID],[Questions].[QuestionID])

and get same result. Changing "!" to "." doesn't help either


That should not work at all. You replaced one too many !

It should have been:

WHERE Questions.QuestionID = IIf(IsLoaded("Questions"),
Forms!Questions.QuestionID, Questions.QuestionID)

But I finally followed your example closely enough to
reproduce the behavior. After some head scratching and more
tests, I conclude that it the fact that
Forms!Questions.QuestionID is a query parameter and that the
prompt occurs before the query starts running. The IIf has
nothing to do with it.

I think you can work around it by not using a parameter and
calling a custom function in a standard module that returns
the ID from the form:

Public Function GetQID()
GetQID = Forms!Questions.QuestionID
End Function

and

WHERE Questions.QuestionID = IIf(IsLoaded("Questions"),
GetQID(), Questions.QuestionID)

--
Marsh

Thanks for coming back, Marsh
I think your theory is right that parameter bit is called before the IIf
clause is evaluated, and the solution you suggested has the same problem.

However this put me on the right track and

Public Function GetQID(StgFrm As String, StgFld As String)

If IsLoaded(StgFrm) Then
GetQID = Forms(StgFrm)(StgFld)
End If

End Function

WHERE Questions.QuestionID
=IIf(IsLoaded("Questions"),GetQID("Questions","Que stionID"),[Questions].[QuestionID])

Thanks everso

Phil

Reply With Quote
  #8  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-22-2010 , 04:33 PM



"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:icbnvo$j31$1 (AT) speranza (DOT) aioe.org:

Quote:
On 21/11/2010 14:09:10, Bob Quintal wrote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ic9lje$78d$1 (AT) speranza (DOT) aioe.org:

Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Quest
io ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending
whether the form is open.

If the form is open, all works as expected giving only the same
question on the form. If the form is closed, The parameter box
comes up asking for a value for Forms!Question!QuestionID, and
regardless of what I put in there, including just pressink the
OK button, all the records in the query show as they should ie
200 odd questions. Why is the "Enter Paramater Box" showing? -
more importantly, how do I stop it showing?

Thanks Phil


IIf() evaluates the 3 passed parameters, whether or not the first
parameter evaluates true or false.



Thanks, Bob

Sorry, I must be a bit thick. What 3rd parameter. Only options are
[Forms]![Questions]![QuestionID] or [Questions]![QuestionID]

Phil
iif() takes 3 parameters,
the first gets evaluated to true or false,
the second is returned if the first is true,
the third is returned if the first is false.

--
Bob Q.
PA is y I've altered my address.

Reply With Quote
  #9  
Old   
Phil
 
Posts: n/a

Default Re: Parameter box showing when it shouldn't - 11-22-2010 , 04:47 PM



On 22/11/2010 22:33:18, Bob Quintal wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:icbnvo$j31$1 (AT) speranza (DOT) aioe.org:

On 21/11/2010 14:09:10, Bob Quintal wrote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ic9lje$78d$1 (AT) speranza (DOT) aioe.org:

Simplifies SQL is

SELECT Questions.Question
FROM Questions
WHERE
(((Questions.QuestionID)=IIf(IsLoaded("Questions") ,[Forms]![Quest
io ns]![QuestionID],[Questions]![QuestionID]))) GROUP BY
Questions.Question;

The full query is more complex, but irrelevant for this question

IsLoaded("FormName") simply returns true or false depending
whether the form is open.

If the form is open, all works as expected giving only the same
question on the form. If the form is closed, The parameter box
comes up asking for a value for Forms!Question!QuestionID, and
regardless of what I put in there, including just pressink the
OK button, all the records in the query show as they should ie
200 odd questions. Why is the "Enter Paramater Box" showing? -
more importantly, how do I stop it showing?

Thanks Phil


IIf() evaluates the 3 passed parameters, whether or not the first
parameter evaluates true or false.



Thanks, Bob

Sorry, I must be a bit thick. What 3rd parameter. Only options are
[Forms]![Questions]![QuestionID] or [Questions]![QuestionID]

Phil

iif() takes 3 parameters,
the first gets evaluated to true or false,
the second is returned if the first is true,
the third is returned if the first is false.

I said I was being a bit thick. See what you mean

Anyway, problem sorted thanks

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.