G
Guest
Rats! After much fiddling, I obviusly need help with this.
Copied existing form (works fine), which uses multiple combo boxes and a
'Go' button to find (filter) records based on selections. Only modified
existing code in the new form to match new combo box names and related
fieldnames. On break, iget the error "Error '2001' - you cancelled the
previous operation" Debug points me to the following line near the bottom of
the Sub:
Me.FilterOn = True
Following is the code concerned:
Private Sub cmdGo_Click()
Dim TheFilter As String
Dim FilterStarted As Boolean
Dim Quote As String
Quote = Chr$(34)
'Dummy filter for all records
TheFilter = "[BeneLName] Like " & Quote & "*" & Quote
'When FilterStarted is true, the string needs an AND next
FilterStarted = False
Me.DataEntry = False
Call ShowForm
Me.NavigationButtons = True
Me.cmdFindCase.Visible = False
Me.cmdDeleteCase.Visible = True
Me.cmdSaveClose.Visible = True
Me.cmdPrintCase.Visible = True
'This builds a filter based on what they enter
If Me.cbo_CaseFileNumber <> "" And Not IsNull(Me.cbo_CaseFileNumber) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [InquiryID] = '" &
Me.cbo_CaseFileNumber & "'"
Else
TheFilter = "[InquiryID] = '" & Me.cbo_CaseFileNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_BradCaseFileNumber <> "" And Not IsNull(Me.cbo_BradCaseFileNumber)
Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [BRADID] = '" &
Me.cbo_BradCaseFileNumber & "'"
Else
TheFilter = "[BRADID] = '" & Me.cbo_BradCaseFileNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_ROCITSIssueNumber <> "" And Not IsNull(Me.cbo_ROCITSIssueNumber)
Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [ROCITSID] = '" &
Me.cbo_ROCITSIssueNumber & "'"
Else
TheFilter = "[ROCITSID] = '" & Me.cbo_ROCITSIssueNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_BeneficiaryLastName <> "" And Not
IsNull(Me.cbo_BeneficiaryLastName) Then
TheFilter = "[BeneLName] = " & Quote & Me.cbo_BeneficiaryLastName & Quote
FilterStarted = True
End If
If Me.cbo_InquirerName <> "" And Not IsNull(Me.cbo_InquirerName) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [InquirerName] = '" &
Me.cbo_InquirerName & "'"
Else
TheFilter = "[InquirerName] = '" & Me.cbo_InquirerName & "'"
FilterStarted = True
End If
End If
If Me.cbo_MedicareNumber <> "" And Not IsNull(Me.cbo_MedicareNumber) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [BeneHICN] = '" &
Me.cbo_MedicareNumber & "'"
Else
TheFilter = "[BeneHICN] = '" & Me.cbo_MedicareNumber & "'"
FilterStarted = True
End If
End If
Me.FilterOn = True
DoCmd.ApplyFilter , TheFilter
If Me.CurrentRecord = 0 Then
MsgBox "Your search returned no records. Please try again"
FilterOn = False
Me.cmdGo.SetFocus
Call HideForm
Else
Call ShowForm
Me.InquiryID.SetFocus
End If
End Sub
I clearly need to modify something, but can't figure out where. Any help
would be greatly appreciated! Thanks in advance.
Copied existing form (works fine), which uses multiple combo boxes and a
'Go' button to find (filter) records based on selections. Only modified
existing code in the new form to match new combo box names and related
fieldnames. On break, iget the error "Error '2001' - you cancelled the
previous operation" Debug points me to the following line near the bottom of
the Sub:
Me.FilterOn = True
Following is the code concerned:
Private Sub cmdGo_Click()
Dim TheFilter As String
Dim FilterStarted As Boolean
Dim Quote As String
Quote = Chr$(34)
'Dummy filter for all records
TheFilter = "[BeneLName] Like " & Quote & "*" & Quote
'When FilterStarted is true, the string needs an AND next
FilterStarted = False
Me.DataEntry = False
Call ShowForm
Me.NavigationButtons = True
Me.cmdFindCase.Visible = False
Me.cmdDeleteCase.Visible = True
Me.cmdSaveClose.Visible = True
Me.cmdPrintCase.Visible = True
'This builds a filter based on what they enter
If Me.cbo_CaseFileNumber <> "" And Not IsNull(Me.cbo_CaseFileNumber) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [InquiryID] = '" &
Me.cbo_CaseFileNumber & "'"
Else
TheFilter = "[InquiryID] = '" & Me.cbo_CaseFileNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_BradCaseFileNumber <> "" And Not IsNull(Me.cbo_BradCaseFileNumber)
Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [BRADID] = '" &
Me.cbo_BradCaseFileNumber & "'"
Else
TheFilter = "[BRADID] = '" & Me.cbo_BradCaseFileNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_ROCITSIssueNumber <> "" And Not IsNull(Me.cbo_ROCITSIssueNumber)
Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [ROCITSID] = '" &
Me.cbo_ROCITSIssueNumber & "'"
Else
TheFilter = "[ROCITSID] = '" & Me.cbo_ROCITSIssueNumber & "'"
FilterStarted = True
End If
End If
If Me.cbo_BeneficiaryLastName <> "" And Not
IsNull(Me.cbo_BeneficiaryLastName) Then
TheFilter = "[BeneLName] = " & Quote & Me.cbo_BeneficiaryLastName & Quote
FilterStarted = True
End If
If Me.cbo_InquirerName <> "" And Not IsNull(Me.cbo_InquirerName) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [InquirerName] = '" &
Me.cbo_InquirerName & "'"
Else
TheFilter = "[InquirerName] = '" & Me.cbo_InquirerName & "'"
FilterStarted = True
End If
End If
If Me.cbo_MedicareNumber <> "" And Not IsNull(Me.cbo_MedicareNumber) Then
If FilterStarted = True Then
TheFilter = TheFilter & " AND [BeneHICN] = '" &
Me.cbo_MedicareNumber & "'"
Else
TheFilter = "[BeneHICN] = '" & Me.cbo_MedicareNumber & "'"
FilterStarted = True
End If
End If
Me.FilterOn = True
DoCmd.ApplyFilter , TheFilter
If Me.CurrentRecord = 0 Then
MsgBox "Your search returned no records. Please try again"
FilterOn = False
Me.cmdGo.SetFocus
Call HideForm
Else
Call ShowForm
Me.InquiryID.SetFocus
End If
End Sub
I clearly need to modify something, but can't figure out where. Any help
would be greatly appreciated! Thanks in advance.