You have cancelled the previous operation

thsoundman

Registered User.
Local time
Yesterday, 22:00
Joined
Sep 4, 2007
Messages
43
Hey all... I have three searchable fields in my query ATM if i search the MO, and the job code by themselves they don't error out. But if i try searching the FName field. It says "You have canceled the previous operation? Can someone help me with this
 

Attachments

Code:
Private Sub txtQuery_Click()
On Error GoTo Err_txtQuery_Click

   Dim strSQL As String
   Dim strWHERE As String

   strSQL = "SELECT * from Panel"
   If Not IsNull(Me.qMO) Then
      strWHERE = " AND [MO] = " & Me.qMO
   End If
   
   If Not IsNull(Me.qCode) Then
      strWHERE = strWHERE & " AND CODE = " & Me.qCode
   End If
   
   If Not IsNull(Me.qFNname) Then
      strWHERE = strWHERE & " AND [FName] like '*" & Me.qFNname & "*'"
   End If
   
   If Len(strWHERE) > 0 Then
      strWHERE = " WHERE " & Mid(strWHERE, 5)
   End If
   strSQL = strSQL & strWHERE
      
   Me.Panel.Form.RecordSource = strSQL

Exit_txtQuery_Click:
    Exit Sub
    
Err_txtQuery_Click:
    MsgBox Err.Description
    Resume Exit_txtQuery_Click

End Sub
I have simplified your code a little to make it easier to read.

It is assumed that you are doing exact matches for the numeric Mo and Code fields and so, unlike FName, I have used the = operator.


Note:
The txt prefix is normally used for unbound text boxes. For a command button, you can use cmd.

You can even further simplify the code if you follow the dynamic query method in the Microsoft article linked to by EMP in your earlier thread
http://www.access-programmers.co.uk/forums/showthread.php?t=135617

Code:
Private Sub cmdSearch2_Click()
   Dim strSQL As String
   Dim strWHERE As Variant
   
   strWHERE = Null
   
   strWHERE = " AND [MO] = " + Me.qMO
   strWHERE = strWHERE & " AND CODE = " + Me.qCode
   strWHERE = strWHERE & " AND [FName] like '*" + Me.qFNname + "*'"
   
   strWHERE = " WHERE " + Mid(strWHERE, 5)
   strSQL = "SELECT * from Panel" & strWHERE
  
   Me.Panel.Form.RecordSource = strSQL
End Sub
It's much neater.
.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom