469,127 Members | 1,305 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,127 developers. It's quick & easy.

print report based on query

12
why won't this work?

I have a form which has a text box: forms!frmCaseLog!tboCaseID the RecordSource for the form is tblCaseLog with the field [lngCaseID]

I would like to print a report with details entered into the form.

For the report RecordSource I have created a query "qryCurrentCaseInfo" which has in the criteria for [lngCaseID] the control above on the form "frmCaseLog"

I have a command button [cmdPrint] to print the report with the code

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrint_Click()
  2.  
  3. Dim stDocName As String
  4.  
  5. DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 
  6.  
  7. With Forms!frmUrgentTriage1 
  8.  
  9.     .tbo2CaseID.SetFocus 
  10.     .tbo2CaseID.Requery 
  11.     .Repaint 
  12.  
  13. End With
  14.  
  15.  
  16.  
  17.     stDocName = "Report1"
  18.     DoCmd.OpenReport stDocName, acNormal
  19.  
  20. End Sub
  21.  
  22.  
If I debug.print the control I get the Case ID value but I cannot get the query to use the Case ID value as the criterion for the report.

what gives? am I missing something?

thanks a bunch!

/jh
Mar 3 '09 #1
1 1158
PianoMan64
374 Expert 256MB
@JohnHo
Hey JohnHo,

You simply need to add the following to your Docmd.OpenReport settings.



Expand|Select|Wrap|Line Numbers
  1. 'OLD WAY
  2. DoCmd.OpenReport stDocName, acNormal 
  3.  
  4. 'NEW WAY
  5.  
  6. DoCmd.OpenReport stDocName, acNormal,,"[tboCaseID]=" & me.lngCaseID
  7.  
  8.  
The last Option if you read the help file for OpenReport, has an option to pass it a query string if you want something limited by a value in a certain field.

Hope that helps,

Joe P.
Mar 5 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Sherwood Botsford | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.