468,134 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Printing a Report from the Current Record on a Sub-Form

112 100+
I am working with Access 2007. I am trying to print a report from the current record on a Subform. My form is comprised of a Main form with a sub-form and another sub-form with in the sub-form.
Main form = Renters Info
Subform = Rental Info
Subform = Dates for rental

I want to print off a report for one rental that lists the info for the rental with the renter information. I have created a button on the Rental subform to print the report. I have tried various codes that I have found on the internet to connect the current record to the report, however it does not work. I keep getting a pop-up box that asks me to “Enter Parameter Value” for the FuntionID. If I enter the right ID it works(wrong Id I get an error), but I don’t want to have to enter the ID as it should just print the current record without asking?
Here are the three codes I have been working with. All with the same result.
Expand|Select|Wrap|Line Numbers
  1. Dim strDocName As String
  2. Dim strWhere As String
  3.     strDocName = "Contract"
  4.     strWhere = "[FunctionID]=" & Me!FunctionID
  5.     DoCmd.OpenReport strDocName, acPreview, , strWhere
  6. End Sub
  7.  
  8. Dim strReportName As String
  9.    Dim strCriteria As String
  10.  
  11.    strReportName = "Contract"
  12.    strCriteria = "[FunctionID]=" & Me![FunctionID] & ""
  13.    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
  14.  
  15. End Sub
  16.  
  17. Dim Condition As String
  18.     Condition = "[FunctionID]=[Forms]![Main]![SubFunctionForm].[Form]![FunctionID])"
  19.     DoCmd.OpenReport "Contract", acViewPreview, , Condition
  20.  
  21. End Sub 
  22.  
I am not sure what I am doing wrong but think it is probably something to do with the printing for a subform? Any Ideas?

Thanks
Feb 13 '12 #1
5 5484
NeoPa
32,036 Expert Mod 16PB
You have two end subs with no start subs. End subs can possibly be omitted but the start subs are nearly always critical.
Feb 13 '12 #2
Redbeard
112 100+
To cleairify, these are the three different codes I have tryed and got the same result.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Contract_Click()
  2. Dim strWhere As String
  3.     strDocName = "Contract"
  4.     strWhere = "[FunctionID]=" & Me!FunctionID
  5.     DoCmd.OpenReport strDocName, acPreview, , strWhere
  6. End Sub
  7.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Contract_Click()
  2. Dim strReportName As String
  3. Dim strCriteria As String
  4.  
  5.     strReportName = "Contract"
  6.     strCriteria = "[FunctionID]=" & Me![FunctionID] & ""
  7.     DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
  8.  
  9. End Sub
  10.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Contract_Click()
  2. Dim Condition As String
  3.      Condition = "[FunctionID]=[Forms]![Main]![SubFunctionForm].[Form]![FunctionID])"
  4.      DoCmd.OpenReport "Contract", acViewPreview, , Condition
  5.  
  6. End Sub
Feb 13 '12 #3
NeoPa
32,036 Expert Mod 16PB
If the reporting of the error is correct then the problem is in your query. The field is probably mis-spelled as [FuntionID]. If that's not it then you need to be more careful with your posts as we can only work with what you post.

Certainly, without errors elsewhere, I would expect your first code example to work assuming the value of [FuntionID] is numeric.
Feb 13 '12 #4
Redbeard
112 100+
I found the problem... It was a bad link between my report and sub-report. Somehow it got linked directly to my table and not to the report itself. Thank for the suggestion of looking in the query, it let me back to the report where the error was.

Many Thanks NeoPa
Feb 13 '12 #5
NeoPa
32,036 Expert Mod 16PB
I think I may have helped accidentally then. Not that I wasn't trying to, of course. Just that the help was more of a by-product of the suggestion than the suggestion itself. Never mind. Any help is helpful at the end of the day ;-)
Feb 13 '12 #6

Post your reply

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

Similar topics

1 post views Thread by SAN CAZIANO | last post: by
4 posts views Thread by John | last post: by
reply views Thread by Spook | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.