Multiple WHERE condition (1 Viewer)

richardw

Registered User.
Local time
Yesterday, 23:14
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
 

JHB

Have been here a while
Local time
Today, 08:14
Joined
Jun 17, 2012
Messages
7,732
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) & " " _
 

bob fitz

AWF VIP
Local time
Today, 07:14
Joined
May 23, 2011
Messages
4,727
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.
 

Cronk

Registered User.
Local time
Today, 16:14
Joined
Jul 4, 2013
Messages
2,772
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
 

richardw

Registered User.
Local time
Yesterday, 23:14
Joined
Feb 18, 2016
Messages
48
Thansk JHB.
It's a number but when i tried it it gave me this error :
compilation error. Expected end of statement
 

richardw

Registered User.
Local time
Yesterday, 23:14
Joined
Feb 18, 2016
Messages
48
Hi Cronk,
It doesn't give error nor a program crash it just run the first condition (teamName)
 

richardw

Registered User.
Local time
Yesterday, 23:14
Joined
Feb 18, 2016
Messages
48
Hi Bob,

It doesn't give error nor a program crash it just run the first condition (teamName)
 

richardw

Registered User.
Local time
Yesterday, 23:14
Joined
Feb 18, 2016
Messages
48
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

Top Bottom