Set two conditions for Find Method in ADO

Amir 181 Reputation points
2021-06-13T10:52:01.18+00:00

I have an ADO recordset and want to retrieve some matching fields in my form. I should set two criteria for the recordset and I use the AND keyword with FOR method, I tried a lot of formats but I get error when I run it.
The code is as follow:
105144-error.png
Private Sub cmdDetailControl_Click()
'Create the necessary recordset and connections
Dim cn As ADODB.Connection
Dim rsInventoryControl As ADODB.Recordset
Dim rsInventoryAssigned As ADODB.Recordset
Dim strSQLInventory As String
Dim strSQLAssigned As String

    'set the connection and recordsets  
    Set cn = New ADODB.Connection  
    Set rsInventoryControl = New ADODB.Recordset  
    Set rsInventoryAssigned = New ADODB.Recordset  
      
    'Create and build recordsets  
    strSQLInventory = "SELECT tblInventory.InventoryID, tblInventoryCategory.CategoryName, tblInventory.InventoryName, tblInventory.InventoryUnit, Sum(tblInventoryTransactionDetail.QtyAdded) AS SumOfQtyAdded, Sum(tblInventoryTransactionDetail.QtyDeducted) AS SumOfQtyDeducted, tblInventoryTransaction.StockID, [SumOfQtyAdded]-[SumOfQtyDeducted] AS Balance " & _  
    "FROM tblInventoryTransaction INNER JOIN ((tblInventory INNER JOIN tblInventoryTransactionDetail ON tblInventory.InventoryID = tblInventoryTransactionDetail.InventoryID) INNER JOIN tblInventoryCategory ON tblInventory.InventoryCategoryID = tblInventoryCategory.InventoryCategoryID) ON tblInventoryTransaction.InventoryTransactionID = tblInventoryTransactionDetail.InventoryTransactionID " & _  
    "GROUP BY tblInventory.InventoryID, tblInventoryCategory.CategoryName, tblInventory.InventoryName, tblInventory.InventoryUnit, tblInventoryTransaction.StockID;"  
    With rsInventoryControl  
    .CursorType = adOpenForwardOnly  
    'open the recordset based on SQL statement using the existing connection  
    .Open strSQLInventory, CurrentProject.Connection  
    End With  
      
    'find the record based on the information in form and subform  
    rsInventoryControl.Find "[InventoryID]= " & Me!frmInventoryPermissionDetailSubform.Form!cboInventoryID & " And [StockID] = " & Me.StockID  
      
     If rsInventoryControl.EOF Then  
        MsgBox "I don't find a record with this Specification", vbOKOnly + vbExclamation, "No Record"  
    Else  
        MsgBox "Paper Inventory: " & rsInventoryControl!Balance & vbCrLf & _  
        " Paper code: " & rsInventoryControl!InventoryID & vbCrLf & _  
        " Stock ID: " & rsInventoryControl!StockID  
    End If  
      
      
      
End Sub  
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
823 questions
0 comments No comments
{count} votes

Accepted answer
  1. DBG 2,301 Reputation points
    2021-06-13T14:47:07.277+00:00

    Okay, I could be wrong since I don't use ADO, but according to this article:

    find-method-ado

    It says:

    "Only a single-column name may be specified in criteria. This method does not support multi-column searches."

    So, as a troubleshooting step, try searching for one column only just to see if the error goes away.

    Hope that helps...

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. DBG 2,301 Reputation points
    2021-06-13T13:29:25.84+00:00

    Hi. Which line is highlighted when you go to debug?


  2. Amir 181 Reputation points
    2021-06-13T13:37:28.357+00:00

    Dear thedbguy,

    Line 17.

    0 comments No comments