Hi All,
I have a Main form with 4 fields used to filter records on a subform. The subform recordsource is a query. Now i am trying to export to excel and pdf whatever results i get after filtering the subform.
Example: Assume that i have 500 records in total before applying the filter. Then get 20 records after applying the filter. I want to have a button which i will click and then export only those 20 records to excel. And have another button to export to PDF.
Can someone help me with the vba code please?
I have attached a picture of my form for you to understand what i mean.
Below is the recordsource of the subform.
Code:
Dim SQL As String
Private Sub CmdSearch_Click()
SQL = "SELECT SALE_TRANSACTION_HISTORY.Sale_Date, SALE_TRANSACTION_HISTORY.Item_Category, SALE_TRANSACTION_HISTORY.Item_Name, SALE_TRANSACTION_HISTORY.Item_Price, SALE_TRANSACTION_HISTORY.QtyOrdered, [Item_Price]*[QtyOrdered] AS Total, SALE_TRANSACTION_HISTORY.Item_Category_ID " _
& " FROM SALE_TRANSACTION_HISTORY" _
& " WHERE Sale_Date >= #" & Format(CDate(Me.TxtStartPeriod), "mm/dd/yyyy") & "# And Sale_Date <= #" & Format(CDate(Me.TxtEndPeriod), "mm/dd/yyyy") & "#" _
& " AND Item_Name LIKE '*" & Me.TxtItem & "*'" _
& " AND SALE_TRANSACTION_HISTORY.Item_Category LIKE '*" & Me.CboItemCategory.Column(1) & "*'" _
& " ORDER BY SALE_TRANSACTION_HISTORY.Sale_Date DESC"
Me.SubSalesReport.Form.RecordSource = SQL
Me.SubSalesReport.Form.Requery
End Sub