Bill Pearson
asked on
Newbie needs help printing from a form.
I'm new to Access. I've searched for 3 days for a solution on the net. I know from all the proper methodologies a report is the preferred solution but in my case, it would be much more beneficial if I could print the data returned from a search form. The Search code works fine but the print report prints ALL the database not just the results returned in SUB btnSearch: Help, Code is attached. Thanks very much.
Option Compare Database
Option Explicit
'Execute Search Based on Input Criteria
'Populate and Display Results on embedded subform
Private Sub btnSearch_Click()
Dim SQL As String
SQL = "SELECT ToolTable.MyPart, ToolTable.Description " _
& "FROM ToolTable " _
& "Where Description LIKE '*" & Me.txtKeywords & "*' " _
& "ORDER BY ToolTable.MyPart "
Me.SubToolList.Form.Record Source = SQL
Me.SubToolList.Form.Requer y
End Sub
' Subroutine Needs to Print Out the Results Obtained Above on Report "rptSearch"
Private Sub btnPrint_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "rptSearch"
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
End Sub
Option Compare Database
Option Explicit
'Execute Search Based on Input Criteria
'Populate and Display Results on embedded subform
Private Sub btnSearch_Click()
Dim SQL As String
SQL = "SELECT ToolTable.MyPart, ToolTable.Description " _
& "FROM ToolTable " _
& "Where Description LIKE '*" & Me.txtKeywords & "*' " _
& "ORDER BY ToolTable.MyPart "
Me.SubToolList.Form.Record
Me.SubToolList.Form.Requer
End Sub
' Subroutine Needs to Print Out the Results Obtained Above on Report "rptSearch"
Private Sub btnPrint_Click()
Dim strReportName As String
Dim strCriteria As String
strReportName = "rptSearch"
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
like what I said , remove this line
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
Assuming your workflow is:
Filter form >> click button to print filtered results
Yes, you would keep:
Filter form >> click button to print filtered results
Yes, you would keep:
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
and replace:Private Sub btnSearch_Click()
Dim SQL As String
SQL = "SELECT ToolTable.MyPart, ToolTable.Description " _
& "FROM ToolTable " _
& "Where Description LIKE '*" & Me.txtKeywords & "*' " _
& "ORDER BY ToolTable.MyPart "
Me.SubToolList.Form.RecordSource = SQL
Me.SubToolList.Form.Requery
End Sub
with:Private Sub btnSearch_Click()
Me.Filter = "[Description]" & " LIKE '*" & Me.txtKeywords & "*' "
End Sub
ASKER
I got a little too excited I guess. When I click the print button, My form pops up in a window but does not print to printer. If I click on the report window and print I only get the header/footer printed.
My goal is to be able to keep open the search form, if the search returns something I want on hard copy to click print button and then come back to original form for another search process.
Sorry for the confusion. Thanks again.
My goal is to be able to keep open the search form, if the search returns something I want on hard copy to click print button and then come back to original form for another search process.
Sorry for the confusion. Thanks again.
it will be better printing the report than printing the form.
ASKER
I think you are probably right. Thanks
ASKER
Just an update. I hate to plead stupidity but it may help someone else who wants to do this.
Rey was right on the first time. The reason my repeat printing attempts didn't work was that
the form itself I was printing in color but the records were suppose to print in black. On my
repeat prints the Black Cartridge had run out. Works perfectly now. So give me the stupid
award but YOUR SOLUTION WORKED PERFECTLY for anyone else that needs to do this.
Thanks
Rey was right on the first time. The reason my repeat printing attempts didn't work was that
the form itself I was printing in color but the records were suppose to print in black. On my
repeat prints the Black Cartridge had run out. Works perfectly now. So give me the stupid
award but YOUR SOLUTION WORKED PERFECTLY for anyone else that needs to do this.
Thanks
good, you got it working. Don't forget to close the thread.
ASKER
I'm not sure if I add this in addition to what I have and leave the
DoCmd.OpenReport strReportName, acViewPreview, , Me.Filter
Line as is.
THanks to both for your help. Very much appreciated