Query criterion by form control unsteady

G

Guest

A combo box was assigned as a criterion in a query like
[Forms]![0019_WorkPlanConsult]![Combo6]. When I updated the combo box and
tried to open the query, Access shows an error message "Microsoft JET
database engine does not recognize '[Forms]![0019_WorkPlanConsult]![Combo6]'
as an effective field or operator" in my language.
But it did work few days ago. Will anyone give any comment about that?
Any comments will be much appreciated.
Thanks in advance!
 
A

Allen Browne

First thing to do would be to turn off Name AutoCorrect.
Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

Then compact the database:
Tools | Database Utilities | Compact/Repair

In Access 2007, it would be:
Office Button | Access Options | Current Database | Name AutoCorrect
followed by:
Office Button | Manage | Compact/Repair

If that does not solve the problem, double-check tha the form is open (not
closed, nor in design view.) You can also check this by opening the
Immediate Window (Ctrl+G), and entering an expression like this:
? [Forms]![0019_WorkPlanConsult]![Combo6]

It is still fails, switch the query to SQL View (View menu in query design.)
Copy the whole SQL statement out to clipboard.
Close, and delete the query.
Compact again.
Now create a new query, switch to SQL View, paste the statement in, and save
it.

If it still fails after that, paste the SQL statement here, and also tell us
these properties of the combo:
Control Source
Row Source
Bound Column
Column Count
Column Widths
Format
 
G

Guest

Hi! Allen,
Thank you very much for your answer.
I am using MS Access 2003.
Following your instruction, however it still not works....
Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Then compact the database:
Tools | Database Utilities | Compact/Repair Also tried....
? [Forms]![0019_WorkPlanConsult]![Combo6] Got the right value.
It is still fails, switch the query to SQL View (View menu in query design.)
Copy the whole SQL statement out to clipboard.
Close, and delete the query.
Compact again.
Now create a new query, switch to SQL View, paste the statement in, and save
it.
Done, but still failed to resolve the problem.
I NOTICED THAT AFTER ALL THE ABOVE ACTIVITIES, ACCESS STILL ADD A BRACKET
AUTOMATICALLY ON "Form!" after I edit the criterion
Forms![0019_WorkPlanConsult]![Combo6] by wizard.

Last, the SQL statement looks like this:
Query Name: 1001PartsTablePCS

SELECT [1004Block].BLK, [1003Sub_Asmbly].Sub_Asmbly,
[1002Pre_Asmbly].Pre_Asmbly, [1001PartsList].Part, [1001PartsList].Part_Side,
[1001PartsList].Aux, [1002PartsTablePCS].P, [1002PartsTablePCS].C,
[1002PartsTablePCS].S, [1001PartsList].Material, [1001PartsList].Thick,
[1001PartsList].Weight, [1008SNO].SNO_ID
FROM (1008SNO INNER JOIN (1007Mega_Section INNER JOIN 1006PES ON
[1007Mega_Section].MS_ID = [1006PES].[1007Mega_Section_ID]) ON
[1008SNO].SNO_ID = [1007Mega_Section].[1008SNO_ID]) INNER JOIN
(1005Pre_Erection INNER JOIN (1004Block INNER JOIN (1003Sub_Asmbly INNER JOIN
(1002Pre_Asmbly INNER JOIN (1002PartsTablePCS INNER JOIN 1001PartsList ON
[1002PartsTablePCS].PartIDFirst = [1001PartsList].PartID) ON
[1002Pre_Asmbly].PA_ID = [1001PartsList].[1002Pre_Asmbly_ID]) ON
[1003Sub_Asmbly].SA_ID = [1002Pre_Asmbly].[1003Sub_Asmbly_ID]) ON
[1004Block].BLK_ID = [1003Sub_Asmbly].[1004Block_ID]) ON
[1005Pre_Erection].PE_ID = [1004Block].[1005Pre_Erection_ID]) ON
[1006PES].PES_ID = [1005Pre_Erection].[1006PES_ID]
WHERE ((([1008SNO].SNO_ID)=[Forms]![0019_WorkPlanConsult]![Combo6]))
ORDER BY [1004Block].BLK, [1003Sub_Asmbly].Sub_Asmbly,
[1002Pre_Asmbly].Pre_Asmbly, [1001PartsList].Part;
these properties of the combo:
Control Source: NIL
Row Source:
SELECT [1008SNO].SNO_ID, [1008SNO].SNO
FROM 1008SNO
ORDER BY [1008SNO].SNO;

Bound Column:1
Column Count:2
Column Widths:0;2
Format: Not assigned

I will keep doing trouble shooting.
Thank you very much!
 
A

Allen Browne

Okay, the combo contains 2 columns.
It stores the SNO_ID value, but displays the SNO value.
Your query is applying it against the SNO_ID field, so that looks right.

Let's try declaring the parameter so Access knows the data type:

1. Open table 1008SNO in design view.
What data type is the SNO_ID field?
If Number, also take note of the Field Size (first property in the lower
pane of property design.) Close the table.

2. Open the query in design view.
Choose Parameters on the Query menu.
Access opens a dialog.
Enter a row such as:
[Forms]![0019_WorkPlanConsult]![Combo6] Long Integer
Use the correct type in the 2nd column.
Save, and then test the query.

If the form is open, and the combo has a value, it should now recognise it.
If it does not recognise it, it will ask you for a value for the parameter.

Let us know how you go.

(I am assuming that this is a normal Access query, not a pass-through
query.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Meitatsu said:
Hi! Allen,
Thank you very much for your answer.
I am using MS Access 2003.
Following your instruction, however it still not works....
Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Then compact the database:
Tools | Database Utilities | Compact/Repair Also tried....
? [Forms]![0019_WorkPlanConsult]![Combo6] Got the right value.
It is still fails, switch the query to SQL View (View menu in query
design.)
Copy the whole SQL statement out to clipboard.
Close, and delete the query.
Compact again.
Now create a new query, switch to SQL View, paste the statement in, and
save
it.
Done, but still failed to resolve the problem.
I NOTICED THAT AFTER ALL THE ABOVE ACTIVITIES, ACCESS STILL ADD A BRACKET
AUTOMATICALLY ON "Form!" after I edit the criterion
Forms![0019_WorkPlanConsult]![Combo6] by wizard.

Last, the SQL statement looks like this:
Query Name: 1001PartsTablePCS
SELECT [1004Block].BLK,
[1003Sub_Asmbly].Sub_Asmbly,
[1002Pre_Asmbly].Pre_Asmbly,
[1001PartsList].Part,
[1001PartsList].Part_Side,
[1001PartsList].Aux,
[1002PartsTablePCS].P,
[1002PartsTablePCS].C,
[1002PartsTablePCS].S,
[1001PartsList].Material,
[1001PartsList].Thick,
[1001PartsList].Weight,
[1008SNO].SNO_ID
FROM (1008SNO
INNER JOIN (1007Mega_Section
INNER JOIN 1006PES
ON [1007Mega_Section].MS_ID = [1006PES].[1007Mega_Section_ID])
ON [1008SNO].SNO_ID = [1007Mega_Section].[1008SNO_ID])
INNER JOIN (1005Pre_Erection
INNER JOIN (1004Block
INNER JOIN (1003Sub_Asmbly
INNER JOIN (1002Pre_Asmbly
INNER JOIN (1002PartsTablePCS
INNER JOIN 1001PartsList
ON [1002PartsTablePCS].PartIDFirst = [1001PartsList].PartID)
ON [1002Pre_Asmbly].PA_ID = [1001PartsList].[1002Pre_Asmbly_ID])
ON [1003Sub_Asmbly].SA_ID = [1002Pre_Asmbly].[1003Sub_Asmbly_ID])
ON [1004Block].BLK_ID = [1003Sub_Asmbly].[1004Block_ID])
ON [1005Pre_Erection].PE_ID = [1004Block].[1005Pre_Erection_ID])
ON [1006PES].PES_ID = [1005Pre_Erection].[1006PES_ID]
WHERE ((([1008SNO].SNO_ID)=[Forms]![0019_WorkPlanConsult]![Combo6]))
ORDER BY [1004Block].BLK,
[1003Sub_Asmbly].Sub_Asmbly,
[1002Pre_Asmbly].Pre_Asmbly,
[1001PartsList].Part;
these properties of the combo:
Control Source: NIL
Row Source:
SELECT [1008SNO].SNO_ID, [1008SNO].SNO
FROM 1008SNO
ORDER BY [1008SNO].SNO;

Bound Column:1
Column Count:2
Column Widths:0;2
Format: Not assigned

I will keep doing trouble shooting.
Thank you very much!
 
G

Guest

Thank you very much, Allen!
I maybe find something helpful.
I tried to remove a "pivot query" [1002PartsTablePCS] which is included in
the query mentioned,[1001PartsTablePCS], and it goes normally w/o the error
message. There must be something wrong to include the query
[1002PartsTablePCS]. This query also goes normally by itself.
the SQL statement of [1002PartsTablePCS] is like:

TRANSFORM Sum([1001PartsList].QTY) AS QTY_sum
SELECT [1002Pre_Asmbly].Pre_Asmbly, [1001PartsList].Part,
First([1001PartsList].PartID) AS PartIDFirst, Sum([1001PartsList].QTY) AS
[SUM_QTY]
FROM 1002Pre_Asmbly INNER JOIN 1001PartsList ON [1002Pre_Asmbly].PA_ID =
[1001PartsList].[1002Pre_Asmbly_ID]
GROUP BY [1002Pre_Asmbly].Pre_Asmbly, [1001PartsList].Part
PIVOT [1001PartsList].Part_Side;

Let me also take time to study your comment.
Thank you!
 
G

Guest

At last I copy the SQL and pasted on VBA code to generate a query with a
constant criterion aqired by VBA statement. like the follows:
"WHERE ((([1008SNO].SNO_ID) = "
[Forms]![0019_WorkPlanConsult]![Combo6] & "))"
It does not answer why but resolved my problem.
I am looking forward to a better solution.
 

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