B
Barry
I have a form with a list box containing Customer names. Since all customers
may not have an associated company name, I made a column in the query of the
listbox rowsource using an IIF statement if the company name ISNULL.
CustName:IIF(IsNull(CompanyName),[LastName] & ", " [FirstName],CompanyName)
which works quite nicely. I want to add an unbound textbox (strSearch) to
the form to search for names based on the characters in the textbox and
change the RowSource accordingly. This is the code in the OnChange of the
textbox.
Dim strSQL As String, Where As String
Where = "[CustName] like '" & Me!strSearch.Text & "*'"
strSQL = "SELECT tblCustomers.CustomerID, IIf(IsNull([CompanyName]),
[LastName] & "", "" & [FirstName], [CompanyName]) as CustName,
tblCustomers.Phone" & vbCr & _
" FROM tblCustomers" & vbCr & _
" Where " & Where
lstCustomers.RowSource = strSQL
Can anyone tell me where I have gone wrong?
Thanks,
Barry
may not have an associated company name, I made a column in the query of the
listbox rowsource using an IIF statement if the company name ISNULL.
CustName:IIF(IsNull(CompanyName),[LastName] & ", " [FirstName],CompanyName)
which works quite nicely. I want to add an unbound textbox (strSearch) to
the form to search for names based on the characters in the textbox and
change the RowSource accordingly. This is the code in the OnChange of the
textbox.
Dim strSQL As String, Where As String
Where = "[CustName] like '" & Me!strSearch.Text & "*'"
strSQL = "SELECT tblCustomers.CustomerID, IIf(IsNull([CompanyName]),
[LastName] & "", "" & [FirstName], [CompanyName]) as CustName,
tblCustomers.Phone" & vbCr & _
" FROM tblCustomers" & vbCr & _
" Where " & Where
lstCustomers.RowSource = strSQL
Can anyone tell me where I have gone wrong?
Thanks,
Barry