R
Rob Parker
I have a form which contains several combo/text boxes and three toggle
buttons in the header section, which are used with a command button to
select the records to be displayed in the form. The code for this button is
as follows:
________________________
Private Sub cmdSelect_Click()
On Error GoTo Err_cmdSelect_Click
Dim strFilter As String
strFilter = ""
strFilter = "Task Like " & Chr$(34) & "*" & cboSelectTaskName & "*" &
Chr$(34)
If cboSelectDepartment <> "" Then
strFilter = strFilter & " " & tglDepartment.Caption & " Department = " &
cboSelectDepartment
End If
If cboSelectWorkplace <> "" Then
strFilter = strFilter & " " & tglWorkplace.Caption & " Workplace = " &
cboSelectWorkplace
End If
If txtSelectTaskNo <> "" Then
strFilter = strFilter & " " & tglTaskNo.Caption & " TaskID = " &
txtSelectTaskNo
End If
Debug.Print strFilter
Filter = strFilter
FilterOn = True
' Enable appropriate browse buttons in form footer
SetNavButtons "FIRST"
Exit_cmdSelect_Click:
Exit Sub
Err_cmdSelect_Click:
If Err.Number = 3021 Then 'No matching records for filter
MsgBox "There are no records matching the select conditions you have
entered " _
& vbNewLine & vbNewLine & "Please try again ...", vbOKOnly, "Select
Failed"
cboSelectTaskName.SetFocus
Resume Exit_cmdSelect_Click
Else
MsgBox Err.Description
Resume Exit_cmdSelect_Click
End If
End Sub
________________________
My problem is that this only works on the first occasion, and then only if
cboSelectTaskName is not null. Subsequent clicks on this command button
produce:
"Run-time error 2001: You cancelled the previous operation"
The offending line of code is indicated as being:
FilterOn = True
The tglXXX.Caption strings are either "AND" or "OR", and the constructed
strFilter works fine if I copy it from the debug window into the form's
Filter property, and then open the form.
Where is this RTE 2001 coming from, and how can I stop it from occurring?
TIA,
Rob
buttons in the header section, which are used with a command button to
select the records to be displayed in the form. The code for this button is
as follows:
________________________
Private Sub cmdSelect_Click()
On Error GoTo Err_cmdSelect_Click
Dim strFilter As String
strFilter = ""
strFilter = "Task Like " & Chr$(34) & "*" & cboSelectTaskName & "*" &
Chr$(34)
If cboSelectDepartment <> "" Then
strFilter = strFilter & " " & tglDepartment.Caption & " Department = " &
cboSelectDepartment
End If
If cboSelectWorkplace <> "" Then
strFilter = strFilter & " " & tglWorkplace.Caption & " Workplace = " &
cboSelectWorkplace
End If
If txtSelectTaskNo <> "" Then
strFilter = strFilter & " " & tglTaskNo.Caption & " TaskID = " &
txtSelectTaskNo
End If
Debug.Print strFilter
Filter = strFilter
FilterOn = True
' Enable appropriate browse buttons in form footer
SetNavButtons "FIRST"
Exit_cmdSelect_Click:
Exit Sub
Err_cmdSelect_Click:
If Err.Number = 3021 Then 'No matching records for filter
MsgBox "There are no records matching the select conditions you have
entered " _
& vbNewLine & vbNewLine & "Please try again ...", vbOKOnly, "Select
Failed"
cboSelectTaskName.SetFocus
Resume Exit_cmdSelect_Click
Else
MsgBox Err.Description
Resume Exit_cmdSelect_Click
End If
End Sub
________________________
My problem is that this only works on the first occasion, and then only if
cboSelectTaskName is not null. Subsequent clicks on this command button
produce:
"Run-time error 2001: You cancelled the previous operation"
The offending line of code is indicated as being:
FilterOn = True
The tglXXX.Caption strings are either "AND" or "OR", and the constructed
strFilter works fine if I copy it from the debug window into the form's
Filter property, and then open the form.
Where is this RTE 2001 coming from, and how can I stop it from occurring?
TIA,
Rob