Multiple WHERE condition

richardw

Registered User.
Local time
Today, 05:55
Joined
Feb 18, 2016
Messages
48
Hi all,

I'm trying to use a WHERE condition that holds two conditions
I succeeded to execute the first condition (teamName) but when I add the second one it doesn't work.

What I want to do is to add this condition to the same code :

Code:
[rsel_frm_viewInitiatives].monthActual='" & Me.cboFilterPeriod.Column(0)

The main code :
Code:
fsql = "SELECT [rsel_frm_viewInitiatives].[idInitiative] AS ID, [rsel_frm_viewInitiatives].[initiativeName] AS Name, [rsel_frm_viewInitiatives].[initiativeType] AS Type, [rsel_frm_viewInitiatives].[teamName] AS Team, [rsel_frm_viewInitiatives].[yearInitialVal] AS [Year], [rsel_frm_viewInitiatives].[initialValInt] AS [INT], [rsel_frm_viewInitiatives].[initialValExt] AS EXT, [rsel_frm_viewInitiatives].[initialValOth] AS OTH, [rsel_frm_viewInitiatives].[monthActual] AS Period, [rsel_frm_viewInitiatives].[typeActual] AS [FTE Type], [rsel_frm_viewInitiatives].[actualFTE] AS Actual, [rsel_frm_viewInitiatives].[remainFTE] AS Remain, [rsel_frm_viewInitiatives].[startMonth] AS [Start Month], [rsel_frm_viewInitiatives].[endMonth] AS [End Month]" & vbCrLf & _
                                    
 " FROM [rsel_frm_viewInitiatives]" & vbCrLf & _
 " WHERE [rsel_frm_viewInitiatives].teamName='" & Me.cboFilterTeam.Column(0) & "'" & vbCrLf & _
 " ORDER BY [rsel_frm_viewInitiatives].[monthActual];"

Thanks in advance :D
 
If monthActual is a string value then:
Code:
 " WHERE [rsel_frm_viewInitiatives].teamName='" & Me.cboFilterTeam.Column(0) & "' AND [rsel_frm_viewInitiatives].monthActual='" & Me.cboFilterPeriod.Column(0) & "' " _
If number:
Code:
 " WHERE [rsel_frm_viewInitiatives].teamName='" &  Me.cboFilterTeam.Column(0) & "' AND  [rsel_frm_viewInitiatives].monthActual=" &  Me.cboFilterPeriod.Column(0) & " " _
 
but when I add the second one it doesn't work.
Can you expand on that. What actually happens, error message, wrong data, program crashes.
Can you post the faulty code that you tried.
 
Your WHERE clause would then read like

WHERE [rsel_frm_viewInitiatives].teamName='" & Me.cboFilterTeam.Column(0) & "' AND [rsel_frm_viewInitiatives].monthActual='" & Me.cboFilterPeriod.Column(0) & "'"
That's if both conditions are to be met, OR if either.

And leave out the vbCrLf's - good for display but not for SQL
 
Hi Cronk,
It doesn't give error nor a program crash it just run the first condition (teamName)
 
Hi Bob,

It doesn't give error nor a program crash it just run the first condition (teamName)
 
Care to share the solution with us, for the benefit of future readers.

I just deleted the ORDER BY condition

Code:
fsql = "SELECT [rsel_frm_viewInitiatives].[idInitiative] AS ID, [rsel_frm_viewInitiatives].[initiativeName] AS Name, [rsel_frm_viewInitiatives].[initiativeType] AS Type, [rsel_frm_viewInitiatives].[teamName] AS Team, [rsel_frm_viewInitiatives].[yearInitialVal] AS [Year], [rsel_frm_viewInitiatives].[initialValInt] AS [INT], [rsel_frm_viewInitiatives].[initialValExt] AS EXT, [rsel_frm_viewInitiatives].[initialValOth] AS OTH, [rsel_frm_viewInitiatives].[monthActual] AS Period, [rsel_frm_viewInitiatives].[typeActual] AS [FTE Type], [rsel_frm_viewInitiatives].[actualFTE] AS Actual, [rsel_frm_viewInitiatives].[remainFTE] AS Remain, [rsel_frm_viewInitiatives].[startMonth] AS [Start Month], [rsel_frm_viewInitiatives].[endMonth] AS [End Month]" & vbCrLf & _
                                   
                                    " FROM [rsel_frm_viewInitiatives]" & vbCrLf & _
                                    
                                    " WHERE [rsel_frm_viewInitiatives].teamName='" & Me.cboFilterTeam.Column(0) & "' AND  [rsel_frm_viewInitiatives].monthActual=" & Me.cboFilterPeriod.Column(0) & " " _
 

Users who are viewing this thread

Back
Top Bottom