PDA

View Full Version : Solved: How to print a report from Search results



RonNCmale
03-18-2008, 08:57 PM
I have the following code behind a search button on my form. When it is clicked it list which field to search and search text. It works great on the form, I can advance the forms records and see each one. I need additional code to be able to print these results to a report. Or another way to get the same results.



Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"

'Filter frmSTG based on search criteria
Form_frmSTG.RecordSource = "select * from STG where " & GCriteria
Form_frmSTG.Caption = "STG (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmSTGSearch"

MsgBox "Results have been filtered."

End If

End Sub

DarkSprout
03-19-2008, 06:41 AM
See below, this entry errored. :banghead:

DarkSprout
03-19-2008, 06:46 AM
This is all done from memory, without any form of testing - but the idea is sound(ish!)

If you want to send the query to a report:
1. Write the basic (all records) query for the report.
2. load the report:
DoCmd.OpenReport "reportName", acViewPreview
3. Send you filterd SQL to the Report ensuring all fields match:
Reports("reportName").RecordSource = strSQL
4. ReQuery the report:
Reports("reportName").FilterOn = True

Hope this helps.

---

"Clarke's First Law: When a distinguished but elderly scientist says that something is possible, he is almost certainly right. When he says it is impossible, he is very probably wrong. Clarke's Second Law: The only way to find the limits of the possible is by going beyond them to the impossible. Clarke's Third Law: Any sufficiently advanced technology is indistinguishable from magic."
Died today: Arthur C. Clarke (1917-2008)

RonNCmale
03-19-2008, 12:53 PM
Attached is a zip file with the search function. If you could please advise me on how to make it print a report from the search results.

DarkSprout
03-20-2008, 06:05 AM
Attached is a zip file with the search function. If you could please advise me on how to make it print a report from the search results.

Can't open the ZIP file, 'Compression Method Not Supported'
This is with Windows pwn Zip handler and with 7Zip.

RonNCmale
03-20-2008, 06:29 AM
compressed with WinZip, I'll compress with 7zip and repost.

RonNCmale
03-20-2008, 06:43 AM
Here it is again, maybe, crossing my fingers you can open. Thanks in advance.

RonNCmale
03-20-2008, 01:18 PM
anyone having trouble opening this database? Really need a solution to this problem.

RonNCmale
03-23-2008, 09:10 PM
A Big Thanks goes out to Carl A. He used my recordset based on my filter to fill a report. Way to go Carl

Carl A
03-24-2008, 06:51 AM
You should post the solution for the benefit of the forum. Thanks!

RonNCmale
03-25-2008, 06:50 AM
Thanks again Carl A