Trouble Using " and '

M

Martin

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.
 
K

Ken Snell \(MVP\)

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
 
M

Martin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top