Results 1 to 4 of 4
  1. #1
    tad888 is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2014
    Posts
    2

    DAO Filter Problem

    I have an issue trying to apply a filter to a recordset. Here's the code:

    ********************
    Dim choice As String
    Dim rset1, rset2 As DAO.Recordset
    Dim dbs as DAO.Database
    Dim var As Variant


    choice = "AND [Qty Avail]<=[Level]"

    set dbs=CurrentDB


    Set rset1 = dbs.OpenRecordset(Me.RecordSource, dbOpenDynaset)
    rset1.Filter = "CodeVendor =" & Me.CodeVendor & choice
    Set rset2 = rset1.OpenRecordset

    *******************

    Whenever the last line is executed, i.e. rset2=rset1.OpenRecordset, I get the following error message:



    <<<Too few parameters, Expected 2>>>

    It used to work before? Maybe an issue with my library?

    Does someone have an idea of what may be creating this issue?

    Thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Why used DAO?

    show the data in a form (continuous form style)
    'apply a filter

    me.filter = "[field] = " & myfilter & "'"
    me.filteron = true

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I, too, am having a hard time understanding the need for DAO.

    As for your code...

    There is a problem with this
    Dim rset1, rset2 As DAO.Recordset

    Access wants the dimensions to be explicit.
    Dim rset1 As DAO.Recordset
    Dim rset2 As DAO.Recordset

    or
    Dim rset1 As DAO.Recordset, rset2 As DAO.Recordset


    As for the error, your are probably wanting to set your recordset to equal a property of the other recordset vs. setting it to equal a Method (OpenRecordset)

  4. #4
    tad888 is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2014
    Posts
    2
    Here's the complete code I have (not the simplified version above). This code is part of an stock (inventory) database. First, I start from a form that shows me, for each of my vendor, parts or components that need to be ordered in a matter to create a purchase order. This code allows me to generate a new purchase order. The filtered object contains the part numbers, qty, prices, etc for one vendor only from which I need to create a purchase order. Here's a more complete version of my code:

    *********************

    Dim rset1 As Recordset
    Dim rset2 As Recordset
    Dim var As Variant


    'Open form Order and create a new Order
    DoCmd.openForm "Order"

    Forms!Order.SetFocus
    Forms!Order.Form.Recordset.AddNew
    Forms!Order![CodeVendor] = Me.CodeVendor


    Set rset1 = CurrentDb.OpenRecordset(Me.RecordSource, dbOpenDynaset)
    rset1.Filter = "CodeVendor =" & Me.CodeVendor
    Set rset2 = rset1.OpenRecordset


    Forms!Order![Sub_form_Purchase_Order].SetFocus

    'Add parts to the new p.o.
    Do While Not rset2.EOF

    'Part number
    With Forms!Order![Sub_form_Purchase_Order]
    .Form.Recordset.AddNew
    ![RéfProduit] = rset2![Réf]
    End With

    'This is to update the other columns of the new part order like name, qty, price, etc
    var = Forms!Order![Sub_form_Purchase_Order].Form.UpdateLigne()

    rset2.MoveNext

    Loop

    Forms!Order![Sub_form_Purchase_Order].Form.Refresh

    rset1.Close
    rset2.Close
    Set rset1 = Nothing
    Set rset2 = Nothing
    Set var = Nothing

    DoCmd.RunCommand acCmdSaveRecord


    End If

    **********************************

    Hoping this may help you understand better,

    Thanks

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

Similar Threads

  1. Filter after pre Filter problem
    By gg80 in forum Programming
    Replies: 6
    Last Post: 07-18-2013, 10:45 AM
  2. Report Filter Problem
    By George in forum Access
    Replies: 7
    Last Post: 05-28-2013, 07:18 PM
  3. filter problem
    By masoud_sedighy in forum Forms
    Replies: 2
    Last Post: 12-15-2011, 01:03 AM
  4. Filter problem
    By Callahan in forum Forms
    Replies: 0
    Last Post: 07-06-2011, 08:03 AM
  5. Filter problem
    By Javad in forum Access
    Replies: 0
    Last Post: 01-22-2011, 01:48 PM

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