ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search form (https://www.excelbanter.com/excel-programming/391184-search-form.html)

אלי

Search form
 
propertyHi!
I am trying to build a search form that extracting records from a list and
present them in a list box. I am using the following code:
' Get SelectStatement.
Dim Position As Integer
Dim SelectStatement As String
Position = InStr(1, Me.Result.RowSource, "WHERE")
SelectStatement = Me.Result.RowSource

'Build WhereCondition.
Dim WhereCondition As String
WhereCondition = "True = True"
If Not IsNull(Me.txtTitle) Then
WhereCondition = WhereCondition & " and Me.Title Like '*" &
Me.txtTitle & "*'"
End If
If Not IsNull(Me.txtAuthorName) Then
WhereCondition = WhereCondition & " and Me.AuthorName Like '*" &
Me.txtAuthorName & "*'"
End If
If Not IsNull(Me.txtJournalName) Then
WhereCondition = WhereCondition & " and Me.JournalName Like '*" &
Me.txtJournalName & "*'"
End If
If Not IsNull(Me.txtYear) Then
WhereCondition = WhereCondition & " and Me.Year Like '*" & Me.txtYear
& "*'"
End If
If Not IsNull(Me.txtKeywords) Then
WhereCondition = WhereCondition & " and Me.Keywords Like '*" &
Me.txtKeywords & "*'"
End If

'Build SQL String.
Dim SQL As String
SQL = SelectStatement & " WHERE " & WhereCondition & ";"

'Pass SQL to ListBox.
Me.Result.RowSource = SQL

and I am stucked in the last line which trigger runtime error '380' that the
RowSource couldn't be set due to invalid property value.

Can anyone suggest why?

Thanks in advance

Eli


All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com