L
Londa Sue
Hello,
I've a search form and am getting a strSQL = BuildWhereString error. I
don't know why and would like some help in resolving. (You're great at
that!)
The form is a search form. Users can search on one of three (or any
combination) of criteria: System, DocumentType, and Status. These are combo
boxes. The form is built on qry_record2. When the search button is clicked,
an error for strSQL is generated "Variable not defined". Here is the code
for BuildWhereString:
Private Function BuildWhereString() As String
Dim strWhere As String
Dim varItemSel As Variant
On Error Resume Next
' ... build "csi system" criterion expression
If Len(Me.cboSystem.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboSystem.Value & "' And "
' ... build "document type" criterion expression
If Len(Me.cboType.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboType.Value & "' And "
' ... build "status" criterion expression
If Len(Me.cboStatus.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboStatus.Value & "' And "
' Strip off the trailing " And " text string
If Len(strWhere) > 0 Then strWhere = Left(strWhere, Len(strWhere) - _
Len(" And "))
BuildWhereString = strWhere
Exit Function
End Function
-------------
Here is the code for cmd_search:
Private Sub cmd_search_Click()
On Error GoTo Err_cmd_search_Click
DoCmd.Hourglass True
' move focus to clear button
Me.cmd_clear.SetFocus
' build sql string for form's RecordSource
strSQL = BuildWhereString
strSQL = "SELECT * FROM " & strMainformRecordSource & _
IIf(strSQL = "", "", " WHERE ") & strSQL & ";"
Me.RecordSource = ""
Me.RecordSource = strSQL
Call SetVisibility(True)
DoCmd.Hourglass False
End Sub
-------
I'm also not getting all the results in a linear fashion. A query may have
four matches, but the form details will only show one. Any ideas why?
(Well, apart from programming, that is.)
Thank you,
Londa Sue
I've a search form and am getting a strSQL = BuildWhereString error. I
don't know why and would like some help in resolving. (You're great at
that!)
The form is a search form. Users can search on one of three (or any
combination) of criteria: System, DocumentType, and Status. These are combo
boxes. The form is built on qry_record2. When the search button is clicked,
an error for strSQL is generated "Variable not defined". Here is the code
for BuildWhereString:
Private Function BuildWhereString() As String
Dim strWhere As String
Dim varItemSel As Variant
On Error Resume Next
' ... build "csi system" criterion expression
If Len(Me.cboSystem.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboSystem.Value & "' And "
' ... build "document type" criterion expression
If Len(Me.cboType.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboType.Value & "' And "
' ... build "status" criterion expression
If Len(Me.cboStatus.Value & "") > 0 Then _
strWhere = strWhere & "ComputerName='" & Me.cboStatus.Value & "' And "
' Strip off the trailing " And " text string
If Len(strWhere) > 0 Then strWhere = Left(strWhere, Len(strWhere) - _
Len(" And "))
BuildWhereString = strWhere
Exit Function
End Function
-------------
Here is the code for cmd_search:
Private Sub cmd_search_Click()
On Error GoTo Err_cmd_search_Click
DoCmd.Hourglass True
' move focus to clear button
Me.cmd_clear.SetFocus
' build sql string for form's RecordSource
strSQL = BuildWhereString
strSQL = "SELECT * FROM " & strMainformRecordSource & _
IIf(strSQL = "", "", " WHERE ") & strSQL & ";"
Me.RecordSource = ""
Me.RecordSource = strSQL
Call SetVisibility(True)
DoCmd.Hourglass False
End Sub
-------
I'm also not getting all the results in a linear fashion. A query may have
four matches, but the form details will only show one. Any ideas why?
(Well, apart from programming, that is.)
Thank you,
Londa Sue