dbTalk Databases Forums  

Print report based on results of query on a form

comp.databases.ms-access comp.databases.ms-access


Discuss Print report based on results of query on a form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rosy
 
Posts: n/a

Default Print report based on results of query on a form - 07-24-2009 , 02:35 PM






I would like to have a report print based on the filtered results of a
form. How do I set this up?

Reply With Quote
  #2  
Old   
Steve
 
Posts: n/a

Default Re: Print report based on results of query on a form - 07-24-2009 , 03:30 PM






Create a query the same as the one your form is based on. Set appropriate
criteria to get the filtered results you want. Use this query as the
recordsource of your report.

Steve
santus (AT) penn (DOT) com


"Rosy" <krmoss (AT) portlite (DOT) com> wrote

Quote:
I would like to have a report print based on the filtered results of a
form. How do I set this up?

Reply With Quote
  #3  
Old   
MGFoster
 
Posts: n/a

Default Re: Print report based on results of query on a form - 07-24-2009 , 04:17 PM



Rosy wrote:
Quote:
I would like to have a report print based on the filtered results of a
form. How do I set this up?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Do as Steve suggested and use VBA in the form like this:

Set up a CommandButton on the form named "cmdPrintReport."

Set the button's Click event to [Event Procedure] and click the Build
button (on the right of the field).

Enter this code in the event procedure's space:

Private Sub cmdPrintReport_Click()

On Error GoTo err_

If Not IsNull(Me.Filter) Then
DoCmd.OpenReport "Report Name", WhereCondition:= Me.Filter
Else
MsgBox "Error: No Filter", vbCritical, "Print Report"
End If

Exit Sub

err_:
MsgBox "Error: " & Err.Description, vbExclamation

End Sub

Be sure to change the "Report Name" to your report's name.

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSmok1IechKqOuFEgEQJz7wCgukJ3UsxVG4XgC1TmFZQ+Hw RMUksAn3XD
4c3c2Nd7ul0yLHb2tfQHxr5q
=GI3O
-----END PGP SIGNATURE-----

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Print report based on results of query on a form - 07-24-2009 , 06:50 PM



Rosy wrote:

Quote:
I would like to have a report print based on the filtered results of a
form. How do I set this up?
You set up criteria you want to limit the report to i the form. Ex, you
want to select a certain employee, certain custoemer, within a date
range, etc. Then you might have a command button for Report and another
for Cancel. If Report button is pressed/selected, you might do
something like
Sub COmmandReport()
Dim strF As String

If Not IsNull(Me.ComboCust) then
strF = "CustomerID = " & Me.ComboCust & " And "
Endif

If Not IsNull(Me.ComboEmp) then
strF = "EmpID = " & Me.ComboEmp & " And "
Endif

If not IsNull(Me.FromDate) Then
strF = "OrdDate => #" & Me.FromDate & "# And "
Endif

If not IsNull(Me.ToDate)/ Then
strF = "OrdDate <= #" & Me.ToDate & "# And "
Endif

'remove the trailing "And" om the filter string
If strF > "" Then strF = left(strF,len(strF)-5)

'now report
Docmd.OpenReport "RptName",,,strF
End Sub

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.