value is in the WCList field of the query [qytbWorkCentreList-Combine].
UNTESTED and it may fail. If it does, try renaming the union query to
qytbWorkCentreListCombine so the brackets are no longer needed and use that in
the sub-query in the where clause. IF it still fails, post back and perhaps I
or someone else can come up with an alternative query. Watch out for newreader
line wraps. I think I've taken care of it, but ...
SELECT [tbWorkorders].[Complete],
[tbWorkorders].[Work center],
[tbWorkorders].[OrderID],
[tbWorkorders].[Earl#start date],
[tbWorkorders].[Order type],
[tbWorkorders].[Order],
[tbWorkorders].[Operation],
[tbWorkorders].[Control key],
[tbWorkorders].[Planner group],
[tbWorkorders].[Opr# short text],
[tbWorkorders].[Normal duration],
[tbWorkorders].[Number],
[tbWorkorders].[Work],
[tbWorkorders].[SystemCondition],
[tbWorkorders].[Purch#req#],
[tbWorkorders].[FunctLocation],
[tbWorkorders].[Description],
[tbWorkorders].[Priority],
[tbWorkorders].[System status],
[tbWorkorders].[Equipment],
[tbWorkorders].[Recipient],
[tbWorkorders].[Std text key],
[tbWorkorders].[Notes]
FROM tbWorkorders
WHERE [tbWorkorders].[Work center] In
(SELECT WClist FROM [qytbWorkCentreList-Combine])
And [tbWorkorders].[Earl#start date]>=
[Forms]![Daily Jobs]![Start_Plan_date]
And [tbWorkorders].[Earl#start date]<=
[Forms]![Daily Jobs]![Finish_Plan_Date]
ORDER BY [tbWorkorders].[Work center],
[tbWorkorders].[Earl#start date],
[tbWorkorders].[Order type] DESC ,
[tbWorkorders].[Order],
[tbWorkorders].[Operation];
Hi John,
I'm not sure what you mean by a sub-query so I'll try to
explain what I am trying to do.
I have a main form called "Daily Jobs", record source -
tbDefaults,
combo box "Work", control source - Work_Centre,
text box "Start_Plan_date", record source - Date_From,
text box "Finish_Plan_Date", record source - Date_To,
This is ok for a single Work Centre but in cases where I
need more than one Work Centre I have a button to open
another form "WorkCentreList" record source -
tbWorkCentreList, where I can enter any numbers of Work
Centres in a data sheet field "Wclist", control source -
Wclist.
I combine the fields from both tables in a union
query, "qytbWorkCentreList-Combine"
SELECT tbWorkCentreList.[WClist]
FROM tbWorkCentreList
UNION SELECT tbDefaults.[Work_Centre]
FROM tbDefaults;
The data sheet sub-form "Daily Job 1", record source -
qDaily_Job_Sheets, SQL below. This is where I use "Like
[qytbWorkCentreListCombine]![WClist]" which gives me a
result from the single entry in the combo box, or the list
from the form WorkCentreList, or both. (I hope this is
making sense) The results from the query are what I want
but I can't edit anything.
SELECT [tbWorkorders].[Complete], [tbWorkorders].[Work
center], [tbWorkorders].[OrderID], [tbWorkorders].
[Earl#start date], [tbWorkorders].[Order type],
[tbWorkorders].[Order], [tbWorkorders].[Operation],
[tbWorkorders].[Control key], [tbWorkorders].[Planner
group], [tbWorkorders].[Opr# short text], [tbWorkorders].
[Normal duration], [tbWorkorders].[Number], [tbWorkorders].
[Work], [tbWorkorders].[SystemCondition], [tbWorkorders].
[Purch#req#], [tbWorkorders].[FunctLocation],
[tbWorkorders].[Description], [tbWorkorders].[Priority],
[tbWorkorders].[System status], [tbWorkorders].
[Equipment], [tbWorkorders].[Recipient], [tbWorkorders].
[Std text key], [tbWorkorders].[Notes]
FROM tbWorkorders, [qytbWorkCentreList-Combine]
WHERE ((([tbWorkorders].[Work center]) Like
[qytbWorkCentreList-Combine]![WClist]) And
(([tbWorkorders].[Earl#start date])>=[Forms]![Daily Jobs]!
[Start_Plan_date] And ([tbWorkorders].[Earl#start date]) <=
[Forms]![Daily Jobs]![Finish_Plan_Date]))
ORDER BY [tbWorkorders].[Work center], [tbWorkorders].
[Earl#start date], [tbWorkorders].[Order type] DESC ,
[tbWorkorders].[Order], [tbWorkorders].[Operation];
SELECT tbWorkCentreList.[WClist]
FROM tbWorkCentreList
This is probably a big ask and I appreciate your assistance
Regards
Nick
.