Access03 Bug - parameters in Query grid

G

Guest

When entering parameter criteria referencing value of form control (ex:
Forms![frmSample]![cboSampleValue]) in QBE grid, Access adds brackets to the
expression, which results in syntax errors (plus can't run the query), and I
can't stop it from happening?

What is going on???
 
M

MGFoster

MarkK said:
When entering parameter criteria referencing value of form control (ex:
Forms![frmSample]![cboSampleValue]) in QBE grid, Access adds brackets to the
expression, which results in syntax errors (plus can't run the query), and I
can't stop it from happening?

What is going on???

Just Access' way of hand-holding. Go into the SQL view & get rid of the
extra brackets Access added, then save the query.
 
V

Van T. Dinh

That shouldn't be the cause of the syntax error. The set [] is simply name
delimiter and the syntax is valid.

The problem may be somewhere else.

Post the entire SQL and the error message you got.
 
G

Guest

Thanks very much for the responses:

To clarify, Access transforms Forms![frmSample]![cboSampleValue] to
[Forms]![frmSample]![cboSampleValue] .

Here is the SQL:
SELECT tblReqsDetail.Type, tblReqsDetail.tag, tblReqsDetail.Name,
tblReqsDetail.version, tblReqsDetail.Description, tblReqsDetail.Owner,
tblReqsDetail.Status, tblReqsDetail.Priority, tblReqsDetail.uda_name,
tblReqsDetail.uda_value
FROM tblReqsDetail
WHERE (((tblReqsDetail.Type)=[Forms]![frmQBF]![cboType]) AND
((tblReqsDetail.Owner)=[Forms]![frmQBF]![cboOwner]) AND
((tblReqsDetail.Status)=[Forms]![frmQBF]![cboStatus]) AND
((tblReqsDetail.uda_value)=[Forms]![frmQBF]![cboOriginator])) OR
((([Forms]![frmQBF]![cboType]) Is Null) AND (([Forms]![frmQBF]![cboOwner]) Is
Null) AND (([Forms]![frmQBF]![cboStatus]) Is Null) AND
(([Forms]![frmQBF]![cboOriginator]) Is Null));

Van T. Dinh said:
That shouldn't be the cause of the syntax error. The set [] is simply name
delimiter and the syntax is valid.

The problem may be somewhere else.

Post the entire SQL and the error message you got.

--
HTH
Van T. Dinh
MVP (Access)



MarkK said:
When entering parameter criteria referencing value of form control (ex:
Forms![frmSample]![cboSampleValue]) in QBE grid, Access adds brackets to
the
expression, which results in syntax errors (plus can't run the query), and
I
can't stop it from happening?

What is going on???
 
V

Van T. Dinh

The transformation is fine. The SQL you posted looks fine also when I
parsed it as:

SELECT tblReqsDetail.Type, tblReqsDetail.tag, tblReqsDetail.Name,
tblReqsDetail.version, tblReqsDetail.Description, tblReqsDetail.Owner,
tblReqsDetail.Status, tblReqsDetail.Priority, tblReqsDetail.uda_name,
tblReqsDetail.uda_value
FROM tblReqsDetail
WHERE
(
((tblReqsDetail.Type)=[Forms]![frmQBF]![cboType]) AND
((tblReqsDetail.Owner)=[Forms]![frmQBF]![cboOwner]) AND
((tblReqsDetail.Status)=[Forms]![frmQBF]![cboStatus]) AND
((tblReqsDetail.uda_value)=[Forms]![frmQBF]![cboOriginator])
) OR
(
(([Forms]![frmQBF]![cboType]) Is Null) AND
(([Forms]![frmQBF]![cboOwner]) Is Null) AND
(([Forms]![frmQBF]![cboStatus]) Is Null) AND
(([Forms]![frmQBF]![cboOriginator]) Is Null)
);

Can you post the full error message?

Also, make sure the BoundColumns of the ComboBoxes correspond to the Field
you are comparing against the ComboBox.
 
G

Gary Walter

Hi Mark,

PMFBI

Its not so much a "bug" as it is
Access thinking it can write your
WHERE clause more efficiently
when it sees all those AND's and OR's
as you save the query (it has nothing to
do with the additional brackets).

You wanted to use the trick of

WHERE

(field 1= parameter1 OR parameter1 IS NULL)

AND

(field2=parameter2 OR parameter2 IS NULL)

AND

(field3=parameter3 OR parameter3 IS NULL);

If you try this with more than a couple of sets,
Access, in its infinite wisdom, thinks it would be
more efficient to say

WHERE

(field1=parameter1
AND
field2=parameter2
AND
field3=parameter3)

OR

(parameter1 IS NULL
AND
parameter2 IS NULL
AND
parameter3 IS NULL);

That isn't going to return *anything*
unless they *all* match their parameters
or the parameters are *all* NULL!

Go back into SQL view and rewrite
in original form above, then save it
from SQL View (I believe Access
won't mess with it then).

Or just rewrite the query using
values from your form in click
event of command button on your
form that runs the query (and forget
using form parameters in queries).

(quick and dirty air code:)

Dim strSQL As String
Dim strWhere As String

strSQL = "SELECT t.Type, t.tag, t.Name, " _
& "t.version, t.Description, t.Owner, " _
& "t.Status, t.Priority, t.uda_name, " _
& "t.uda_value " _
& "FROM tblReqsDetail AS t"

If Len(Trim(Me!cboType & "")) > 0 then
strWhere = " WHERE (t.[Type] = '" & me!cboType & "')"
Else
strWhere = " WHERE (1=1)"
End If

If Len(Trim(Me!cboOwner & "")) > 0 then
strWhere = strWhere & " AND (t.Owner = '" & me!cboOwner & "')"
Else
'no parameter
End If

If Len(Trim(Me!cboStatus & "")) > 0 then
strWhere = strWhere & " AND (t.Status =' " & me!cboStatus & "')"
Else
'no parameter
End If

If Len(Trim(Me!cboOriginator & "")) > 0 then
strWhere = strWhere & " AND (t.uda_value = '" & me!cboOriginator & "')"
Else
'no parameter
End If

strSQL = strSQL & strWhere
'view new sql in Immediate window
Debug.Print strSQL

'(must have reference set to DAO)
'redefine your query
CurrentDb.QueryDefs("nameofyourquery").SQL = strSQL

'now do something with your new query



Code above assumes all your WHERE fields were
type TEXT...if any were not, then delete the
single quotes surrounding me!cboxxxx

Apologies again for butting in,

gary

MarkK said:
Thanks very much for the responses:

To clarify, Access transforms Forms![frmSample]![cboSampleValue] to
[Forms]![frmSample]![cboSampleValue] .

Here is the SQL:
SELECT tblReqsDetail.Type, tblReqsDetail.tag, tblReqsDetail.Name,
tblReqsDetail.version, tblReqsDetail.Description, tblReqsDetail.Owner,
tblReqsDetail.Status, tblReqsDetail.Priority, tblReqsDetail.uda_name,
tblReqsDetail.uda_value
FROM tblReqsDetail
WHERE (((tblReqsDetail.Type)=[Forms]![frmQBF]![cboType]) AND
((tblReqsDetail.Owner)=[Forms]![frmQBF]![cboOwner]) AND
((tblReqsDetail.Status)=[Forms]![frmQBF]![cboStatus]) AND
((tblReqsDetail.uda_value)=[Forms]![frmQBF]![cboOriginator])) OR
((([Forms]![frmQBF]![cboType]) Is Null) AND (([Forms]![frmQBF]![cboOwner])
Is
Null) AND (([Forms]![frmQBF]![cboStatus]) Is Null) AND
(([Forms]![frmQBF]![cboOriginator]) Is Null));

Van T. Dinh said:
That shouldn't be the cause of the syntax error. The set [] is simply
name
delimiter and the syntax is valid.

The problem may be somewhere else.

Post the entire SQL and the error message you got.

--
HTH
Van T. Dinh
MVP (Access)



MarkK said:
When entering parameter criteria referencing value of form control (ex:
Forms![frmSample]![cboSampleValue]) in QBE grid, Access adds brackets
to
the
expression, which results in syntax errors (plus can't run the query),
and
I
can't stop it from happening?

What is going on???
 
G

Gary Walter

One more thing....

If you decide to keep using the
form controls as parameters in
your query, be sure to declare
their type.

Select "Query" from the top menu
and click on "Parameters..." at bottom
of drop-down menu. Add all your
form parameters and choose its
appropriate data type, i.e.,

Parameters DataType
[Forms]![frmQBF]![cboType] Text


good luck,

gary
 
G

Guest

Thanks for the help - I cleaned up the query in SQL view, then saved from SQL
view. Also, I needed to fix the BoundColumns of the Combo boxes.

Van T. Dinh said:
The transformation is fine. The SQL you posted looks fine also when I
parsed it as:

SELECT tblReqsDetail.Type, tblReqsDetail.tag, tblReqsDetail.Name,
tblReqsDetail.version, tblReqsDetail.Description, tblReqsDetail.Owner,
tblReqsDetail.Status, tblReqsDetail.Priority, tblReqsDetail.uda_name,
tblReqsDetail.uda_value
FROM tblReqsDetail
WHERE
(
((tblReqsDetail.Type)=[Forms]![frmQBF]![cboType]) AND
((tblReqsDetail.Owner)=[Forms]![frmQBF]![cboOwner]) AND
((tblReqsDetail.Status)=[Forms]![frmQBF]![cboStatus]) AND
((tblReqsDetail.uda_value)=[Forms]![frmQBF]![cboOriginator])
) OR
(
(([Forms]![frmQBF]![cboType]) Is Null) AND
(([Forms]![frmQBF]![cboOwner]) Is Null) AND
(([Forms]![frmQBF]![cboStatus]) Is Null) AND
(([Forms]![frmQBF]![cboOriginator]) Is Null)
);

Can you post the full error message?

Also, make sure the BoundColumns of the ComboBoxes correspond to the Field
you are comparing against the ComboBox.

--
HTH
Van T. Dinh
MVP (Access)



MarkK said:
Thanks very much for the responses:

To clarify, Access transforms Forms![frmSample]![cboSampleValue] to
[Forms]![frmSample]![cboSampleValue] .

Here is the SQL:
SELECT tblReqsDetail.Type, tblReqsDetail.tag, tblReqsDetail.Name,
tblReqsDetail.version, tblReqsDetail.Description, tblReqsDetail.Owner,
tblReqsDetail.Status, tblReqsDetail.Priority, tblReqsDetail.uda_name,
tblReqsDetail.uda_value
FROM tblReqsDetail
WHERE (((tblReqsDetail.Type)=[Forms]![frmQBF]![cboType]) AND
((tblReqsDetail.Owner)=[Forms]![frmQBF]![cboOwner]) AND
((tblReqsDetail.Status)=[Forms]![frmQBF]![cboStatus]) AND
((tblReqsDetail.uda_value)=[Forms]![frmQBF]![cboOriginator])) OR
((([Forms]![frmQBF]![cboType]) Is Null) AND (([Forms]![frmQBF]![cboOwner])
Is
Null) AND (([Forms]![frmQBF]![cboStatus]) Is Null) AND
(([Forms]![frmQBF]![cboOriginator]) Is Null));
 
G

Guest

Thanks for the help; unfortunately, I have to pass the query parameters
through the form, as the users are insisting on easy, multi-criteria
filtering at runtime.
 
J

John Vinson

Thanks for the help; unfortunately, I have to pass the query parameters
through the form, as the users are insisting on easy, multi-criteria
filtering at runtime.

That's what Gary is telling you how to do.

Define the Parameters collection of the query to indicate the name of
the form and the controls on the form into which the users will enter
their easy, multicriteria filtering.

John W. Vinson[MVP]
 

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