Help with SQL for combobox (1 Viewer)

shafara7

Registered User.
Local time
Today, 16:06
Joined
May 8, 2017
Messages
118
I have a form with a subform in it. I recently just added a new table in the subform query.
I'm having trouble rearranging the FORM sql into my combobox sql, because now there is a new line in my subform record source (in bold).
Code:
FROM (tblMessanlage 
RIGHT JOIN (tblMessaufgaben 
RIGHT JOIN (tblFOLand 
INNER JOIN (tblPrioritaet 
RIGHT JOIN (tblPulk 

RIGHT JOIN ((tblBauphasen  
RIGHT JOIN (qryStammdatenBelegung      
INNER JOIN tblMessauftrag 
ON (qryStammdatenBelegung.indFOLand = tblMessauftrag.indFOLand) 
AND (qryStammdatenBelegung.txtTeilesachnummer = tblMessauftrag.txtTeilesachnummer)) 
ON tblBauphasen.lngReihenfolge = tblMessauftrag.indBauphase)
INNER JOIN qryBelegungPerson 
ON (tblMessauftrag.indFOLand = qryBelegungPerson.indFOLand) 
AND (tblMessauftrag.txtTeilesachnummer = qryBelegungPerson.txtTeilesachnummer) ) 

ON tblPulk.ID = tblMessauftrag.indPulk) 
ON tblPrioritaet.ID = tblMessauftrag.indPrioritaet) 
ON tblFOLand.ID = tblMessauftrag.indFOLand) 
ON tblMessaufgaben.ID = tblMessauftrag.indMessaufgabe) 
ON tblMessanlage.ID = tblMessauftrag.indAbweichendeMessanlage) 
[B]LEFT JOIN qryMessauftragPerson ON tblMessanlage.ID = qryMessauftragPerson.ID [/B]

My combobox FROM sql is as follows
Code:
FROM (tblPulk  
RIGHT JOIN (tblFOLand 
INNER JOIN (tblMessanlage   
RIGHT JOIN (tblMessaufgaben 
RIGHT JOIN (tblPrioritaet   
RIGHT JOIN (tblBauphasen 
RIGHT JOIN (qryStammdatenBelegung 
INNER JOIN tblMessauftrag 
ON (qryStammdatenBelegung.indFOLand = tblMessauftrag.indFOLand) 
AND (qryStammdatenBelegung.txtTeilesachnummer = tblMessauftrag.txtTeilesachnummer)) 
ON tblBauphasen.lngReihenfolge = tblMessauftrag.indBauphase) 
ON tblPrioritaet.ID = tblMessauftrag.indPrioritaet) 
ON tblMessaufgaben.ID = tblMessauftrag.indMessaufgabe) 
ON tblMessanlage.ID = tblMessauftrag.indAbweichendeMessanlage) 
ON tblFOLand.ID = tblMessauftrag.indFOLand) 
ON tblPulk.ID = tblMessauftrag.indPulk) 

INNER JOIN qryBelegungPerson 
ON (qryBelegungPerson.indFOLand = tblMessauftrag.indFOLand) 
AND (tblMessauftrag.txtTeilesachnummer = qryBelegungPerson.txtTeilesachnummer)

I tried adding the bolded sql at the last combobox sql but I got an Error:
error 3075:Syntax error(missing operator) in query expression 'qryBelegungPerson
ON (qryBelegungPerson.indFOLand = tblMessauftrag.indFOLand) AND (tblMessauftrag.txtTeilesachnummer = qryBelegungPerson.txtTeilesachnummer) LEFT JOIN qryMessauftragPerson ON tblMessanlage.ID = qryMessauftragPerson.ID '


I am not really good in sql and I am not the one who arranged the code for the combobox.
Thus, I don't know why is the arrangement of the sql of the combobox differs from that in the record source.
Can somebody explain?
 

Orthodox Dave

Home Developer
Local time
Today, 15:06
Joined
Apr 13, 2017
Messages
218
Hi Shafara,
I'm no good in sql either, but what works is to test it in a query design, then modify the query, switch to sql view and copy the resulting sql. You can clearly see what is going on in query design and the query builder translates it all into sql for you.
 

shafara7

Registered User.
Local time
Today, 16:06
Joined
May 8, 2017
Messages
118
Well I did. The sql (the first code above) is actually from query sql-view.
I don't get why the person who write the code for the combobox did not follow the exact sequence from the query.
 

Orthodox Dave

Home Developer
Local time
Today, 15:06
Joined
Apr 13, 2017
Messages
218
And when you added the extra bit, did you first add this in Query Design View and then read off the sql?
 

shafara7

Registered User.
Local time
Today, 16:06
Joined
May 8, 2017
Messages
118
Yep. First I added the new table that I want in the Query Design. Then I save it, and changed to SQL-view, the code is already there.
I don't know if I should rearrange the sequence of the sql manually or not. :(
 

Orthodox Dave

Home Developer
Local time
Today, 15:06
Joined
Apr 13, 2017
Messages
218
Sounds like you're doing what I would do. I assumed you tested running the query from the query designer. If it runs, the sql should be right, except for criteria expressions that look up from forms etc (e.g. "xyz = '" & string & "'").
 

Orthodox Dave

Home Developer
Local time
Today, 15:06
Joined
Apr 13, 2017
Messages
218
Hi Shafara,

Just a thought - did you remember the semicolon ";" at the end of the sql code?

The source sql code for the combobox would be different from that of the form itself because the combobox has a particular function within the form. I can't say more than that because I don't have sufficient info. However, studying the arrangement of the tables in query design view should show where the differences lie.

I understand the difficulty of taking over someone else's code and trying to understand why they did it a certain way. I have seen it from both ends! In fact I have to re-learn the code I wrote myself a lot of the time!
 

shafara7

Registered User.
Local time
Today, 16:06
Joined
May 8, 2017
Messages
118
I have founfd the arrangement for the SQL.
Code:
FROM (tblMessanlage 
LEFT JOIN qryMessauftragPerson 
ON tblMessanlage.ID = qryMessauftragPerson.ID) 
RIGHT JOIN (tblMessaufgaben 
RIGHT JOIN (tblFOLand 
INNER JOIN (tblPrioritaet 
RIGHT JOIN (tblPulk 
RIGHT JOIN ((tblBauphasen 
RIGHT JOIN (qryStammdatenBelegung 
INNER JOIN tblMessauftrag 
ON (qryStammdatenBelegung.indFOLand = tblMessauftrag.indFOLand) 
AND (qryStammdatenBelegung.txtTeilesachnummer = tblMessauftrag.txtTeilesachnummer))
ON tblBauphasen.lngReihenfolge = tblMessauftrag.indBauphase) 
INNER JOIN qryBelegungPerson 
ON (tblMessauftrag.indFOLand = qryBelegungPerson.indFOLand) 
AND (tblMessauftrag.txtTeilesachnummer = qryBelegungPerson.txtTeilesachnummer)) 
ON tblPulk.ID = tblMessauftrag.indPulk) 
ON tblPrioritaet.ID = tblMessauftrag.indPrioritaet) 
ON tblFOLand.ID = tblMessauftrag.indFOLand) 
ON tblMessaufgaben.ID = tblMessauftrag.indMessaufgabe) 
ON tblMessanlage.ID = tblMessauftrag.indAbweichendeMessanlage

Though I am still not sure why it has to be that way. There is quite a difference with the old SQL on my first post.
 

Orthodox Dave

Home Developer
Local time
Today, 15:06
Joined
Apr 13, 2017
Messages
218
I see just 2 differences from the original Code. This part has been moved from the end to the beginning:
Code:
LEFT JOIN qryMessauftragPerson 
ON tblMessanlage.ID = qryMessauftragPerson.ID

and you have changed some of the bracketing "()". The bracketing is a complex nightmare and I'm sure a lot it could be removed without problems, but the important question is, does it work now?
 

shafara7

Registered User.
Local time
Today, 16:06
Joined
May 8, 2017
Messages
118
Yes it is working like a charm :)
Gonna mark this threas ad solved.
 

Users who are viewing this thread

Top Bottom