 |
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 26th, 2006, 04:47 PM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

January 27th, 2006, 09:05 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
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
|

January 27th, 2006, 02:17 PM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 30th, 2006, 08:54 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
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
|

February 13th, 2006, 02:55 PM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

February 13th, 2006, 05:09 PM
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

February 14th, 2006, 12:21 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
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.
|

February 14th, 2006, 02:01 PM
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |