Trouble Using " and '

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need help in using the proper double quotation in a defined text string.
This code is based in a previous response on limiting content of one combo
box from what's selected in a another combo box. I already made one combo box
work on a simple query, but here I got some complexity since I need to add an
expression in my limited knowledge on using single and double quotations is
not helping my find the correct way to write it.

Dim strSQL1 as String

strSQL1 = "SELECT [Unit-State].Unit, [Unit-State].State FROM [Unit-State]"
strSQL1 = strSQL1 & " WHERE ((([Unit-State].State)=IIf(" & Me![GasTypeCode]
strSQL1 = strSQL1 & "=Vac Or " & Me![Combo1]
strSQL1 = strSQL1 & "=PVac,PV,P))) ORDER BY [Unit-State].Unit;"
Me!Combo1.RowSource = strSQL1

I want to limit that whenever Me!Combo1 is "Vac" or "PVac", my query
criteria is filtered by "PV", otherwise my query criteria should be filtered
by "P"

Thanks.
 
Dim strSQL1 as String, strIf As String
If Me![GasTypeCode] = "Vac" Or Me![GasTypeCode] = "PVac" Then
strIf = "PV"
Else
strIf = "P"
End If
strSQL1 = "SELECT [Unit-State].Unit, [Unit-State].State FROM [Unit-State]"
strSQL1 = strSQL1 & " WHERE [Unit-State].State='" & strIf & "'"
strSQL1 = strSQL1 & " ORDER BY [Unit-State].Unit;"
Me!Combo1.RowSource = strSQL1
 
Brilliant!!

Ken Snell (MVP) said:
Dim strSQL1 as String, strIf As String
If Me![GasTypeCode] = "Vac" Or Me![GasTypeCode] = "PVac" Then
strIf = "PV"
Else
strIf = "P"
End If
strSQL1 = "SELECT [Unit-State].Unit, [Unit-State].State FROM [Unit-State]"
strSQL1 = strSQL1 & " WHERE [Unit-State].State='" & strIf & "'"
strSQL1 = strSQL1 & " ORDER BY [Unit-State].Unit;"
Me!Combo1.RowSource = strSQL1

--

Ken Snell
<MS ACCESS MVP>


Martin said:
I need help in using the proper double quotation in a defined text string.
This code is based in a previous response on limiting content of one combo
box from what's selected in a another combo box. I already made one combo
box
work on a simple query, but here I got some complexity since I need to add
an
expression in my limited knowledge on using single and double quotations
is
not helping my find the correct way to write it.

Dim strSQL1 as String

strSQL1 = "SELECT [Unit-State].Unit, [Unit-State].State FROM [Unit-State]"
strSQL1 = strSQL1 & " WHERE ((([Unit-State].State)=IIf(" &
Me![GasTypeCode]
strSQL1 = strSQL1 & "=Vac Or " & Me![Combo1]
strSQL1 = strSQL1 & "=PVac,PV,P))) ORDER BY [Unit-State].Unit;"
Me!Combo1.RowSource = strSQL1

I want to limit that whenever Me!Combo1 is "Vac" or "PVac", my query
criteria is filtered by "PV", otherwise my query criteria should be
filtered
by "P"

Thanks.
 
Back
Top