Results 1 to 5 of 5
  1. #1
    desastrux is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    1

    Displaying an ADO Recordset in Immediate Window

    Hey everyone, I am stuck on this whole ADO thing. We never used it in class and now I have to use it in my final project. I have the entire project done, except for the last little part, which I can't figure out.



    Code:
    Public Function ADO_ListBooksPublishedYear(yearPublished As Integer)
    
    
        Dim rst As ADODB.Recordset
        Dim strSQL As String
        
        strSQL = "Select datepart('yyyy', pubdate) as bookYear from tblBooks"
    
    
        Set rst = New ADODB.Recordset
        rst.Open strSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly, adCmdText
        
        MsgBox "There are " & rst.RecordCount & "records in the unfiltered Recordset"
        
        rst.Filter = "bookYear = yearPublished"
        
        MsgBox "There are " & rst.RecordCount & "records in the filtered Recordset"
        
    
    
    End Function
    This is what I have so far. I can't get the filter to work right either. It won't allow me to use the yearPublished variable in the filter. Also I am supposed to display the results from the Recordset after filtering in the immediate window.

    I'm not looking for someone to do this for me, just to steer me in the right direction. I have been searching google for a while trying to figure this out. Would really appreciate any help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    As answered elsewhere:

    You have to concatenate the variable's value into the filter string. You'd use

    Debug.Print

    to output to the Immediate window, as shown here:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    yearPublished is a variable. Must concatenate variables.

    rst.Filter = "bookYear=" & yearPublished

    Displaying results of recordset in immediate window would involve reading each record and Debug.Print the data from the fields in a loop.

    While Not rst.EOF
    Debug.Print rst!bookYear
    Wend
    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.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I guess I misread "I'm not looking for someone to do this for me, just to steer me in the right direction."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe I got just a little carried away with helpfulness.
    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.

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

Similar Threads

  1. How to Select second Recordset from first recordset
    By FrustratedAlso in forum Programming
    Replies: 28
    Last Post: 05-10-2012, 05:45 PM
  2. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  3. get window nfo
    By alcoool in forum Access
    Replies: 3
    Last Post: 01-18-2010, 09:58 AM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 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