Problem with SQL statement (1 Viewer)

sven2

Registered User.
Local time
Today, 18:45
Joined
Apr 28, 2007
Messages
297
Hello,


who can help me with a wrong SQL?
I am trying all day to get this to work without any result ...

I have two working SQL query's with an union and now I want to build
a the last query and this doesn't work.

It goes wrong when I want to define the OR statement:

"' OR '" & [Forms]![FrmRapportering]![cbopapiersoort] & "' = 'ALLE PAPIERSOORTEN')
OR " & [Forms]![FrmRapportering]![cboGramgewicht] & " = 'ALLE GRAMGEWICHTEN')

When I use these statements I get an error wrong SQL.

The complete SQL:

strSQL = " SELECT TblMachine.Machinenaam, TblMoederrollen.Datum, TblMoederrollen.Moederrolnummer, TblPapiersoorten.Papiersoort, TblPapiersoorten.Gramgewicht, TblKwaliteitgegevens.Kwaliteitsnaam, TblKwaliteitswaarde.Kwaliteitswaarde, TblMoederrolOpmerking.Opmerking, TblKwaliteitgegevens.Rapportering " & _
" FROM TblKwaliteitswaarde INNER JOIN TblMoederrollen ON TblKwaliteitswaarde.Moederrolnummer = TblMoederrollen.Moederrolnummer LEFT OUTER JOIN TblMoederrolOpmerking ON TblMoederrollen.Moederrolnummer = TblMoederrolOpmerking.Moederrolnummer INNER JOIN TblPapiersoorten ON TblMoederrollen.PapiersoortID = TblPapiersoorten.PapiersoortID INNER JOIN TblKwaliteitgegevens ON TblKwaliteitswaarde.KwaliteitID = TblKwaliteitgegevens.KwaliteitID INNER JOIN TblMachine ON TblMoederrollen.MachineID = TblMachine.MachineID " & _
" WHERE (TblKwaliteitgegevens.Rapportering = 1) AND (TblMachine.machinenaam = '" & [Forms]![FrmRapportering]![cbomachine] & "') AND (TblPapiersoorten.Papiersoort = '" & [Forms]![FrmRapportering]![cbopapiersoort] & "' OR '" & [Forms]![FrmRapportering]![cbopapiersoort] & "' = 'ALLE PAPIERSOORTEN') And (Tblpapiersoorten.Gramgewicht = " & [Forms]![FrmRapportering]![cboGramgewicht] & " OR " & [Forms]![FrmRapportering]![cboGramgewicht] & " = 'ALLE GRAMGEWICHTEN') AND (TblMoederrollen.Datum BETWEEN '" & [Forms]![FrmRapportering]![txtbegindatum2] & "' AND '" & [Forms]![FrmRapportering]![txteinddatum2] & "') " & _
" ORDER BY TblMoederrollen.Moederrolnummer "


Thanks in advance,
Sven.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:45
Joined
Aug 30, 2003
Messages
36,133
You don't want to surround the field to apply criteria with single quotes, only the value. If you still have trouble, a tool to use to figure out the problem is to add:

Debug.Print strSQL

right after that, and examine the finished SQL string in the Immediate window. If you don't see the problem, post the SQL here.
 

Users who are viewing this thread

Top Bottom