Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a report based on a query with variables from a form. 1

Status
Not open for further replies.

Rubius

Programmer
May 12, 2000
57
CA
I have a query with 5 fields. 2 of the fields have a couple variables. What I'm doing is displaying a report based on selected values on the form. <br>Ok so in the query the 2 fields are just integers, one says Between [Clockstart] and [clockend]<br>the other says<br>Between [jobstart] and [jobend]<br><br>My form has fields clocks, clocke, jobs, jobe. What I need to know how to do is send those fields on the form to the report. Obviously when you open the report it prompts for those variables, I want to automatically fill those variables.<br><br>Any question let me know!<br>Thanks Again..
 
I assume that you have controls on the report that correspond with the controls on the form.&nbsp;&nbsp;Lets make sure we're on the same page regarding them<br><br>frmYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>rptYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>On the click event of the command button(I also assume that you are using one) you enter:<br><br>DoCmd.OpenReport &quot;rptYourNew&quot;<br>Reports![rptYourNew]![txtClockStart] = Me.txtClockStart<br>Reports![rptYourNew]![txtClockEnd] = Me.txtClockEnd<br>Reports![rptYourNew]![txtJobStart] = Me.txtJobStart<br>Reports![rptYourNew]![txtJobEnd] = Me.txtJobEnd<br><br>All this does is pass the values from the form to the report just like you are sending the values to query.&nbsp;&nbsp;<br><br>Let me know how it turns out.<br><br>Bob<br><br>
 
I assume that you have controls on the report that correspond with the controls on the form.&nbsp;&nbsp;Lets make sure we're on the same page regarding them<br><br>frmYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>rptYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>On the click event of the command button(I also assume that you are using one) you enter:<br><br>DoCmd.OpenReport &quot;rptYourNew&quot;<br>Reports![rptYourNew]![txtClockStart] = Me.txtClockStart<br>Reports![rptYourNew]![txtClockEnd] = Me.txtClockEnd<br>Reports![rptYourNew]![txtJobStart] = Me.txtJobStart<br>Reports![rptYourNew]![txtJobEnd] = Me.txtJobEnd<br><br>All this does is pass the values from the form to the report just like you are sending the values to query.&nbsp;&nbsp;<br><br>Let me know how it turns out.<br><br>Bob<br><br>
 
I assume that you have controls on the report that correspond with the controls on the form.&nbsp;&nbsp;Lets make sure we're on the same page regarding them<br><br>frmYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>rptYourNew: txtClockStart, txtClockEnd, txtJobStart and txtJobEnd.<br><br>On the click event of the command button(I also assume that you are using one) you enter:<br><br>DoCmd.OpenReport &quot;rptYourNew&quot;<br>Reports![rptYourNew]![txtClockStart] = Me.txtClockStart<br>Reports![rptYourNew]![txtClockEnd] = Me.txtClockEnd<br>Reports![rptYourNew]![txtJobStart] = Me.txtJobStart<br>Reports![rptYourNew]![txtJobEnd] = Me.txtJobEnd<br><br>All this does is pass the values from the form to the report just like you are sending the values to query.&nbsp;&nbsp;<br><br>Let me know how it turns out.<br><br>Bob<br><br>
 
Sorry, there seems to be something weird about the submit post button today.
 
I don't believe you can assign values to a report field after the report has been opened.<br><br>This is the easiest way to do it.&nbsp;&nbsp;Assuming the following<br><br>Report and Form text box names:<br>txtClockStart, txtClockEnd, txtJobStart, txtJobEnd.<br><br><br><b>On the report</b><br>In the control source property for each text box, enter the following:<br><br>txtClockStart:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=[Forms]![YourFormName]![txtClockStart]<br>txtClockEnd:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=[Forms]![YourFormName]![txtClockEnd]<br>txtJobStart:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=[Forms]![YourFormName]![txtJobStart]<br>txtJobEnd.:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=[Forms]![YourFormName]![txtJobEnd]<br><br>In the On Close Event put the following: (second line only)<br><br>Private Sub Report_Close()<br>&nbsp;&nbsp;&nbsp;&nbsp;Forms!YourFormName.Visible = True<br>End Sub<br><br><br><b>On the Form</b><br>On the On Click Event of the button that opens your report enter the following (second and third lines only) if your form is not a maximized form. If it is, you don't need the&nbsp;&nbsp;visible = False line.<br><br>Private Sub Button_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;Me.Visible = False<br>&nbsp;&nbsp;&nbsp;&nbsp;Docmd.OpenReport &quot;YourReportName&quot;, acPreview<br>End Sub<br><br><br>That's it! Let me know if you have problems.<br>Hope it helps <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top