468,251 Members | 1,479 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Preview Report on Form to include subform

I have added a "Preview Report" button on my main Form Page to mainly "print preview" current page including the 1st subform and I already designed the Report Page for it. But for some reason it pulls out all the report. I am currently using the below SQL. I also made it to a point where it prints the current record but it does not include 1st subform.
Please Help!
Access 2003
Vista

Private Sub Preview_Report_Click()
On Error GoTo Err_Preview_Report_Click
Dim stDocName As String
Dim strWhere As String

stDocName = "Purchase Order Entry"
strWhere = [Purchase Order ID] = "& Forms![Purchase Order ID]![Purchase Order ID]"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "Purchase Order Entry", acPreview, , strWher
Exit_Preview_Report_Click:
Exit Sub
Err_Preview_Report_Click:
MsgBox Err.Description
Resume Exit_Preview_Report_Click

End Sub
Feb 4 '08 #1
4 4810
MMcCarthy
14,534 Expert Mod 8TB
Replace ...

strWhere = [Purchase Order ID] = "& Forms![Purchase Order ID]![Purchase Order ID]"

with ...

strWhere = "[Purchase Order ID]=" & Forms![Purchase Order ID]![Purchase Order ID]
Feb 5 '08 #2
I'm Getting some Pop Up "Microsoft Access can't find the form 'Purchase Order ID' referred in a Macro Expression or Visual Basic Code."

My Main Form is 'Purchase Order Entry'
My Sub Form is 'Inventory Transactions'
My Report Name is "Purchase Order Entry'

Any ideas?
Thanks again!
JT


Replace ...

strWhere = [Purchase Order ID] = "& Forms![Purchase Order ID]![Purchase Order ID]"

with ...

strWhere = "[Purchase Order ID]=" & Forms![Purchase Order ID]![Purchase Order ID]
Feb 5 '08 #3
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

If [Purchase Order ID] is on the main form:

strWhere = "[Purchase Order ID]=" & Forms![Purchase Order Entry]![Purchase Order ID]

If [Purchase Order ID] is on the subform:

strWhere = "[Purchase Order ID]=" & Forms![Purchase Order Entry]![Inventory Transactions].Form![Purchase Order ID]
Feb 5 '08 #4
I tried the main form, the first one you requested and it brought all the reports as it was doing before:
strWhere = "[Purchase Order ID]=" & Forms![Purchase Order Entry]![Purchase Order ID]

I tried the second one and I have a pop up 'Microsoft Access cannot find the field inventory transactions' referred in your transactions'. But then I have changed the Inventory Transactions (Table) to 'Inventory Transactions Subform'.
And it still shows all the record one by one. I'm still trying to restrict to basically show Main Form and Subform on the current view and be able to print review.

I made it last night where it basically print preview the main form only on a current view but how do you add the subform to it.

Here's the website that I followed and it works, now how do you add subform?
http://www.databasedev.co.uk/report_from_form_record.html

and the example code that I use for single Main form:

Private Sub cmdPrintPreview_Click()

Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "rptSalespersonContact"
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]


DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End If
End Sub

Hopefully it make sense. Let me know if there are any information you may need.
Thanks again for your patience.
John
Feb 5 '08 #5

Post your reply

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

Similar topics

3 posts views Thread by Illya Havsiyevych | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.