Printing a selected record in 1 form in another form

T

TedT

Hi,
I have a simple check keeping database that also prints out checks on laser
single sheet checks. I created a form to enter the check data, and then a
form to print the check. This print form only has the pertinent info and is
spaced to fill in the blanks on the laser check. It worked fine until I
added a second check record. Now when I hit the print button, it always
prints all the records. I want it to print the record data that is in the
"EnterCheck" form in the "PrintrCheck" form. Here is the current code that
does the printing and is run when I click on the print button on the
"EnterCheck" form, I have not been able to get it to only print the data
which is displayed in the current form.

Private Sub PrintCheck_Click()
Dim stDocName As String
Dim MyForm As Form

stDocName = "PrintrCheck"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut
DoCmd.SelectObject acForm, MyForm.Name, False
End Sub
 
S

strive4peace

Hi Ted,

make a report to print the check

since you already have a form to do it, it is easy to make the report.

1. base the report on the same Recordsource
2. open design view of form
3. copy all controls
4. go to design view of report
5. paste

then ...

'~~~~~~~~~~
Private Sub PrintCheck_Click()
'save record if changes have been made
if me.dirty then me.dirty = false

if me.NewRecord then
msgbox "You are not on a current record" _
,,"Cannot print check"
exit sub
end if

Dim stDocName As String

stDocName = "PrintCheckReportName"
DoCmd.OpenReport stDocName _
, acViewPreview _
, , "RecordID=" & Me.RecordID

End Sub
'~~~~~~~~~~~~~

WHERE
RecordID is the name of your primary key field and exists on your form
as well as on your report (it can be hidden)

btw, your previous code would work too -- IF you set a filter for the
current record but it is best to use reports for printing ... besides,
then you'd have to remove the filter...

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
Top