Full Version: Sub Form Problem
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
udellj
I have a label on my form that when clicked prints a report based on the current record displayed on my form. The report is based on a query. The query has the following as the criteria: [Forms]![Completed_PAs]![ID]. The code for the label on the form is: DoCmd.OpenReport "All_Request_Letters_Report", acViewPreview. It works fine when you only open the subform. When you open the parent form, and the subform is loaded, I get an enter parameter value when I click the label. I was thinking I would have to do something with setfocus to the subform but I'm not quite sure. Any help can be appreciated.

Edited by: udellj on Wed Jan 5 8:30:46 EST 2005.
DoubleD
Welcome to UA. You've got several options depending on whether the subform is ever opened on it's own, or it is always a subform.

If it's always a subform, you can just change your reference in the query, or remove the query filter and put a where clause in the OpenReport line.
Query Filter: [Forms]![MainFormName]![Completed_PAs].[Form]![ID]
or
DoCmd.OpenReport OpenReport "All_Request_Letters_Report", acViewPreview, ,"[ID] = " & Forms!MainFormName!Completed_PAs.Form!ID
udellj
Thanks for your help. Unfortunately it didn't work however, it did get me thinking in the right direction. The finished working code is simply:
DoCmd.OpenReport "All_Request_Letters", , , "[ID]=" & Me![ID]
I thank you for your help. It would have been a while before I really turned down that avenue. Thanks again

Edited by: udellj on Thu Jan 6 12:57:17 EST 2005.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.