Search code examples
ms-accessvbams-access-2016

Access: Print selected records form query


I really don't know how to start this. I have a report, that takes records from a query. The query itself takes the records from a table. Now I want to be able to select the records in the query by the id manually. But there is no connection between the records, so I can't say 'give me all records between id x and y'. Also, there is not the count of records always changing. I want a user to be able to say: 'okay, I need to print all the data of these x ids'. how can I archive this?


Solution

  • you can create the object using Querydef and used this to change your query at runtime based on the user slected criteria.

    try like this

    Dim query_1 as string
    
    query_1 = "Select * from Table1 where ID  = 'Your ID'"
    
    CurrentDb.QueryDefs("Report_Query").sql = query_1 
    

    than open the report or make pdf ..