Results 1 to 8 of 8
  1. #1
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71

    RecordSetWrapper multiple criteria not working - type mismatch

    im trying to openrecordset using rsw - Northwind custom module that parses the select statement-
    If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & OrderID And "[transaction type]" <> 1) Then

    So this basically is saying to open Inventory Transactions table where customer order ID = OrderID and Transaction type is not 1.

    Should I be using different syntax for this or did I mess up on a quotation or & somewhere.



    Thanks,
    Saud

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Needs to be an SQL statement that sets the rsw object variable, assuming you declared the rsw variable. Is it ADO or DAO recordset? Should post the full procedure.

    For DAO:
    Set rsw = CurrentDb.OpenRecordset("SELECT * FROM[ Inventory Transactions] WHERE [Customer Order ID] = " & Me.OrderID & " And [transaction type]<>1;")

    For ADO:
    rsw.Open "SELECT * FROM [Inventory Transactions] WHERE [Customer Order ID] = " & Me.OrderID & " And [transaction type]<>1;"

    Now what do you want to do with the recordset?

    Since you tried this within an If Then conditional, maybe you just need to use DLookup()?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71
    June. I have a feeling you have not had much time with the Northwind database. RecordSetWrapper is a module. Let me paste it in for you

    Code:
    Option Compare DatabaseOption Explicit
    
    
    Private m_rs As DAO.Recordset2
    
    
    
    
    Public Function GetRecordsetClone(rs As DAO.Recordset2) As DAO.Recordset2
        If Not m_rs Is Nothing Then
            Debug.Assert False ' This is only designed to be used once
        Else
            Set m_rs = rs.Clone
            Set GetRecordsetClone = m_rs
        End If
    End Function
    
    
    
    
    Public Function OpenRecordset(Domain As String, _
                                  Optional Criteria As String = "1=1", _
                                  Optional OrderBy As String, _
                                  Optional RecordsetType As DAO.RecordsetTypeEnum = dbOpenDynaset, _
                                  Optional RecordsetOptions As DAO.RecordsetOptionEnum _
                                  ) As Boolean
        
        
        If Not m_rs Is Nothing Then
            ' Close the recordset so it can be re-used
            CloseRecordset
        End If
        
        Dim strSQL As String
        strSQL = "SELECT * FROM [" & Domain & "] WHERE " & Criteria
        
        If OrderBy <> "" Then
            strSQL = strSQL & " ORDER BY " & OrderBy
        End If
        
        On Error GoTo ErrorHandler
        Set m_rs = CurrentDb.OpenRecordset(strSQL, RecordsetType, RecordsetOptions)
        OpenRecordset = True
    
    
    Done:
        Exit Function
    ErrorHandler:
        ' verify the private Recordset object was not set
        Debug.Assert m_rs Is Nothing
        
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.OpenRecordset", "strSQL = " & Chr(34) & strSQL & Chr(34)) Then Resume
    End Function
    
    
    
    
    Public Function Delete() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.Delete
        Delete = True
        
    Done:
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.Delete") Then Resume
    End Function
    
    
    
    
    Public Function AddNew() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.AddNew
        AddNew = True
        
    Done:
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.AddNew") Then Resume
    End Function
    
    
    
    
    Public Function Edit() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.Edit
        Edit = True
        
    Done:
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.Edit") Then Resume
    End Function
    
    
    
    
    Public Function Update() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.Update
        Update = True
        
    Done:
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.Update") Then Resume
    End Function
    
    
    
    
    Public Function MoveNext() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.MoveNext
        MoveNext = True
        
    Done:
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.MoveNext") Then Resume
    End Function
    
    
    
    
    Public Function CloseRecordset() As Boolean
        On Error GoTo ErrorHandler
        
        m_rs.Close
        CloseRecordset = True
        
    Done:
        Set m_rs = Nothing
        Exit Function
    ErrorHandler:
        ' Resume statement will be hit when debugging
        If eh.LogError("RecordsetWrapper.CloseRecordset") Then Resume
    End Function
    
    
    
    
    Public Property Get Recordset() As DAO.Recordset2
        Set Recordset = m_rs
    End Property
    
    
    
    
    Private Sub Class_Terminate()
        If Not m_rs Is Nothing Then
            m_rs.Close
            Set m_rs = Nothing
        End If
    End Sub
    and the code that used this function
    Code:
    Function Delete(OrderID As Long) As Boolean
            Dim rsw As New RecordSetWrapper
            
                If rsw.OpenRecordset("order details", "[Order ID] = " & OrderID) Then
                With rsw.Recordset
                    If Not .EOF Then
                        Do While Not .EOF
                           Delete = rsw.Delete
                            
                            .MoveNext
                        Loop
                    End If
                End With
            End If
            If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & OrderID And "[transaction type]" <> 1) Then
                With rsw.Recordset
                    If Not .EOF Then
                        Do While Not .EOF
                         Delete = rsw.Delete
                            
                            .MoveNext
                        Loop
                    End If
                End With
            End If
            Set rsw = Nothing
            
        
              If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
                Delete = rsw.Delete
            End If
            End Function
    Basically it works with single critera as in the 1st and 3rd ifs. But I can't seem to get it to work with the 2nd if with the multiple criteria

    Also Please check my databse attached for the other issues i have posted. I have compacted and repaired it and made it under 2mb

    Please let me know if there is anything I can do to make the database more efficient. Somehow it seems like im using hacks for what should be properly coded.

    Appreciate your help.
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    True, I am aware of Northwind (I think there are several variations) but never worked with.

    Try:

    If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & Me.OrderID & " And [transaction type] <> 1") Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71
    Thank you for your help this works - If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & OrderID & " And [transaction type]<>1")

    it was just a matter of the placement of the & and "" which you illustrated in the DAO

  6. #6
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71
    i can't use me.X in a public function. is this normal. always says "invalid use of ME keyword"

  7. #7
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71
    may I know the logic behind the quotations and & as to when to use them.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    i can't use me.X in a public function. is this normal. always says "invalid use of ME keyword"
    "Me" is a short cut for "Forms!FormName" or "Reports!ReportName". Therefore, it will not work in a standard module - only in code behind forms/reports


    If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = "
    I would have also used brackets around "[Inventory Transactions]" because of the space in the name.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Date type mismatch in criteria expression
    By ahmed sami in forum Access
    Replies: 2
    Last Post: 02-17-2015, 11:37 AM
  2. Query criteria Type Mismatch
    By wolfm in forum Queries
    Replies: 17
    Last Post: 04-30-2014, 10:12 AM
  3. Replies: 4
    Last Post: 09-04-2012, 09:17 PM
  4. data type mismatch in criteria expression
    By broecher in forum Access
    Replies: 4
    Last Post: 09-10-2010, 08:29 AM
  5. Replies: 4
    Last Post: 10-26-2009, 05:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums