Results 1 to 6 of 6
  1. #1
    Mick99 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    58

    MS Access Filtering Query Recordset

    Hi All, I am having issues trying to filter a recordset. I have the first recordset that gives me a result for “RScoloumdetail(1)” and that value I am trying to use to filter the second query to only return results matching the result of “RScoloumdetail(1)”

    I have the “RScoloumdetail(1)” returning the correct result of “MT” and I am trying to use this to filter a query called [Qry Email Attachments] and where the field value [RA] is equal to RScoloumdetail(1)")

    This is the code and the error I get
    Set coldetail = dbsCheck.OpenRecordset("Select [Qry Email Attachments] where [RA]= RScoloumdetail(1)")

    Click image for larger version. 

Name:	Capture Error.PNG 
Views:	15 
Size:	16.4 KB 
ID:	29092



    Any help would be greatly appreciated.

  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,644
    RScoloumdetail(1) is a field in [Qry Email Attachments]? If it isn't, then this won't work because cannot reference field in a table that is not included in the query.

    And why use WHERE? Why not do a JOIN between table and query linking on RA and RScoloumdetail(1)?

    Advise not to use spaces or punctuation/special characters (underscore only exception) in names. If used, enclose in [ ].

    Post the full SQL statements.
    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
    Mick99 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    58
    RScoloumdetail(1) is from the first query "[Qry Emails Tracking]" which i loop through to get a single value and simply need to use that to filter the second query, if that makes sense.

    Set dbsCheck = CurrentDb
    Set rstRecords = dbsCheck.OpenRecordset("Select * From [Qry Emails Tracking]")
    If rstRecords.RecordCount = 0 Then
    MsgBox "Sorry, There is no Data for this selection.", vbInformation, "No Data"
    Exit Sub
    Else
    FileName = "Email Correspondence " & " " & RScoloumdetail(1)
    End If

    Dim DocumentName As String
    Dim AttachRecords As DAO.Recordset
    Dim Attachmentcoloumdetail As Variant
    Dim rst As DAO.Recordset
    Dim RA As String
    Dim ParentRole As String

    ParentRole = RScoloumdetail(1)
    Set Attachmentcoloumdetail = dbsCheck.OpenRecordset("[Qry Email Attachments] where [Qry Email Attachments]![RA] = ParentRole")

  4. #4
    Mick99 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    58
    Set Attachmentcoloumdetail = dbsCheck.OpenRecordset("[Qry Email Attachments] where [Qry Email Attachments]![RA] = ParentRole")

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Variables must be concatenated.

    ("[Qry Email Attachments] where [Qry Email Attachments]![RA] = '" & ParentRole & "'")

    Don't see any looping structure.

    Is RScoloumdetail(1) a field in rstRecords? If you want to reference a field of recordset: rstRecords![RScoloumdetail(1)]

    And setting a Variant variable to a recordset is not something I've ever seen.
    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.

  6. #6
    Mick99 is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    58
    Hi June7, this has been solved with the code below. I greatly appreciate your help with this issue.


    Set Attachmentcoloumdetail = dbsCheck.OpenRecordset("Select * FROM [Qry Email Attachments] WHERE [RA] = '" & RScoloumdetail(1) & "'")
    Attached Thumbnails Attached Thumbnails Capture Error 4.PNG  
    Last edited by Mick99; 06-14-2017 at 06:05 PM. Reason: solved

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

Similar Threads

  1. Replies: 3
    Last Post: 05-17-2017, 10:45 AM
  2. Replies: 7
    Last Post: 04-15-2015, 02:47 PM
  3. Replies: 6
    Last Post: 12-03-2013, 11:14 PM
  4. Recordset Filtering
    By George in forum Access
    Replies: 9
    Last Post: 05-27-2012, 10:10 AM
  5. create table filtering a recordset
    By JJCHCK in forum Programming
    Replies: 5
    Last Post: 09-27-2011, 01:11 AM

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