M
Matt P
Hello!
Alright so I am just trying to tidy up my code a little bit. I have a
Select Case statement that I used and I have it so it runs some sql /
query based on the option box they chose. That works perfect, my
problem was when I went to tidy my code up I added the strings that I
had to copy and paste to each "Case":
Dim strcmbSearchComp As String
Dim strlstCompanyNames As String
Dim strlstAddresses As String
strcmbSearchComp = "SELECT DISTINCT tblContacts.fldCity " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE " & strContactType & _
"GROUP BY tblContacts.fldCity;"
strlstCompanyNames = "SELECT tblContacts.fldContactsID,
tblContacts.fldAddress " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE (((tblContacts.fldCity) =
[cmbSearchComp])) " & _
"GROUP BY tblContacts.fldAddress,
tblContacts.fldContactsID, Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1), tblHistory.fldType " & _
"HAVING " & strContactType & _
"ORDER BY Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1);"
strlstAddresses = "SELECT tblContacts.fldContactsID,
tblContacts.fldAddress " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE (((tblContacts.fldCity) = [cmbSearchComp])) "
& _
"GROUP BY tblContacts.fldAddress,
tblContacts.fldContactsID, Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1), tblHistory.fldType " & _
"HAVING " & strContactType & _
"ORDER BY Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1);"
There are three strings... Here is an example of one of my strings:
Case 2
'Insurance Companies
Me.RecordSource = "qryMainSortByInsurance"
'cmbSearchComp & lstAddresses
strContactType = "(((tblHistory.fldType) = 'INSURANCE'))"
'lstCompanyNames
strContactType2 = "(((tblContacts.fldCity)=[cmbSearchComp])
AND ((tblHistory.fldType)= 'INSURANCE'))"
Me.cmbSearchComp.RowSource = strcmbSearchComp
lstCompanyNames.RowSource = strlstCompanyNames
lstAddresses.RowSource = strlstAddresses
Me.cmbSearchComp.Value = ""
Me.lstCompanyNames.Value = ""
Me.Refresh
It gives me an error saying "Syntax error in WHERE clause" which is
the nested string "strcmbSearchComp"
So basically it comes down to this question... Can I nest strings
inside strings and if so, how?
Thanks,
Matt P
Alright so I am just trying to tidy up my code a little bit. I have a
Select Case statement that I used and I have it so it runs some sql /
query based on the option box they chose. That works perfect, my
problem was when I went to tidy my code up I added the strings that I
had to copy and paste to each "Case":
Dim strcmbSearchComp As String
Dim strlstCompanyNames As String
Dim strlstAddresses As String
strcmbSearchComp = "SELECT DISTINCT tblContacts.fldCity " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE " & strContactType & _
"GROUP BY tblContacts.fldCity;"
strlstCompanyNames = "SELECT tblContacts.fldContactsID,
tblContacts.fldAddress " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE (((tblContacts.fldCity) =
[cmbSearchComp])) " & _
"GROUP BY tblContacts.fldAddress,
tblContacts.fldContactsID, Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1), tblHistory.fldType " & _
"HAVING " & strContactType & _
"ORDER BY Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1);"
strlstAddresses = "SELECT tblContacts.fldContactsID,
tblContacts.fldAddress " & _
"FROM tblContacts INNER JOIN tblHistory ON
tblContacts.fldContactsID=tblHistory.fldContactID " & _
"WHERE (((tblContacts.fldCity) = [cmbSearchComp])) "
& _
"GROUP BY tblContacts.fldAddress,
tblContacts.fldContactsID, Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1), tblHistory.fldType " & _
"HAVING " & strContactType & _
"ORDER BY Mid$(tblContacts.fldAddress,InStr
(tblContacts.fldAddress,' ')+1);"
There are three strings... Here is an example of one of my strings:
Case 2
'Insurance Companies
Me.RecordSource = "qryMainSortByInsurance"
'cmbSearchComp & lstAddresses
strContactType = "(((tblHistory.fldType) = 'INSURANCE'))"
'lstCompanyNames
strContactType2 = "(((tblContacts.fldCity)=[cmbSearchComp])
AND ((tblHistory.fldType)= 'INSURANCE'))"
Me.cmbSearchComp.RowSource = strcmbSearchComp
lstCompanyNames.RowSource = strlstCompanyNames
lstAddresses.RowSource = strlstAddresses
Me.cmbSearchComp.Value = ""
Me.lstCompanyNames.Value = ""
Me.Refresh
It gives me an error saying "Syntax error in WHERE clause" which is
the nested string "strcmbSearchComp"
So basically it comes down to this question... Can I nest strings
inside strings and if so, how?
Thanks,
Matt P