p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   print current record on another form (http://p2p.wrox.com/showthread.php?t=37659)

jcellens January 26th, 2006 04:47 PM

print current record on another form
 
i need a button on a form that when clicked will automatically print just the current record on another form. how can i code the event procedure of this command button to do this?

SerranoG January 27th, 2006 09:05 AM

Can you clarify what you would like to do? I don't know how to interpret your words "will automatically print just the current record on another form." Do you mean...

1) You're on Form 1 and the button will take the record showing on Form 2 and print it to a piece of paper, or

2) You're on Form 1 and the button will take the record showing on Form 1 and make a copy of it and put it on Form 2?



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

jcellens January 27th, 2006 02:17 PM

i mean

1) You're on Form 1 and the button will take the record showing on Form 2 and print it to a piece of paper, or



SerranoG January 30th, 2006 08:54 AM

Well, there are a few ways to do this.

If both forms are open and Form 2 has a print report button, you can shift focus to Form 2, activate its print button, shift focus back to Form 1.

Me.Form2.SetFocus
cmdPrintButton_Click
Me.Form1.SetFocus

I'm using fake control names Form1, Form2 and cmdPrintButton. Use your real names.

If Form 2 is not open but its report is based on the same query as Form 2, you don't even have to open Form 2. Just open the report it's based on from From 1's print report button.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

jcellens February 13th, 2006 02:55 PM

i would like to use the second option you mentioned.

i have tried this already by creating a 'print form' button on Form1 that is linked to Form2, however i don't know how to get it to only print 1 record and not all records. i want the button on Form1 to print the current record from Form2


kindler February 13th, 2006 05:09 PM

My suggestion: Cheat.

Forms suck for printing, so what you do is create a report with all the same info as the form, then set the report's record source equal to a query that would bring up only the value currently on form2. Make sure you also set the record source for the report equal to (in this example) qryReport.

Pseudocode:
Me.Form2.SetFocus
varIndex = Forms![Form2]![Index]
strReportQry = "SELECT * " & _
"FROM qryForm2Query " & _
"WHERE [qryForm2Query].[Index] = '" & varIndex & "' ;"

Set dbs = CurrentDb

dbs.QueryDefs.Refresh

For Each qdf In dbs.QueryDefs
    If qdf.Name = "qryReport" Then
        dbs.QueryDefs.Delete qdf.Name
    End If
Next qdf

Set qdfPassThrough = dbs.CreateQueryDef("qryReport")
qdfPassThrough.SQL = strReportQry
qdfPassThrough.ReturnsRecords = True

Set dbs = Nothing

DoCmd.OpenReport "rptReportName", acViewNormal


SerranoG February 14th, 2006 12:21 PM

Although Kindler's suggestion will work, it's kinda overkill. You just need one command line.

To print a report for one record showing on Form2 based on a print button on Form 1 you need only just set a WHERE parameter on the command to print. That is, on Form 1's print button's ON CLICK event, you put something like

DoCmd.OpenReport "Name of Report", acPrintPreview, , "[lngRecNo] = " & Forms.Form2.Form.txtRecNo

Where you replace "Name of Report" with the name of the report; and you replace lngRecNo with the real field in Form2 corresponding with that record number; and you replace Form2 with the real name of your second form; and you replace txtRecNo with the real name of the textbox in Form2 that holds the record number bound to lngRecNo.

kindler February 14th, 2006 02:01 PM

True enough Serrano, I just copied the code from a project in which the tables and form display precluded the use of a single index and made a query the only painless way of doing it.



All times are GMT -4. The time now is 02:20 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.