João serras-pereira
asked on
how to address a report control from a form in ms/access vba
I need to change, from a button in a form, the source of a subreport.
currently, my code is
Reports![sreport_fichaProx imidade].R eport.Reco rdSource = Forms![_commonVariables]![ strSetSQL]
Reports![sreport_fichaProx imidade].R eport.Requ ery
DoCmd.OpenReport "fichaProximidadeFrame", acViewPreview
but I am getting an error as the [sreport_fichaProximidade] control is unknown
How should I refer to it?
thanks for the help
currently, my code is
Reports![sreport_fichaProx
Reports![sreport_fichaProx
DoCmd.OpenReport "fichaProximidadeFrame", acViewPreview
but I am getting an error as the [sreport_fichaProximidade]
How should I refer to it?
thanks for the help
ASKER
Hi.
I need to postpone this by a bit...
my code was perfectly working and, when I pasted in your solution, in a button on the form, I am suddenly getting the error 459 "object does not support this class of events"
I know it's a different matter but do you have a clue, or shall I open a new question?
Screen-Shot-2016-11-13-at-11.16.26.png
I need to postpone this by a bit...
my code was perfectly working and, when I pasted in your solution, in a button on the form, I am suddenly getting the error 459 "object does not support this class of events"
I know it's a different matter but do you have a clue, or shall I open a new question?
Screen-Shot-2016-11-13-at-11.16.26.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> "not work in a ACCDE file"
that is true. You can change the record source of a report (or form) in its OPEN event if you deploy an ACCDE. The Recordsource can be passed in OpenArgs or be a database property or be read from the form, ...
Rather than this, however, if you base the report on a query, you can change the SQL of the query before the report is opened. This will work also in an ACCDE.
that is true. You can change the record source of a report (or form) in its OPEN event if you deploy an ACCDE. The Recordsource can be passed in OpenArgs or be a database property or be read from the form, ...
Rather than this, however, if you base the report on a query, you can change the SQL of the query before the report is opened. This will work also in an ACCDE.
ASKER
well... something weird is now happening.
My code is:
Private Sub btn_reportProximidade_Clic k()
Dim strSetSQL As String
DoCmd.OpenReport "fichaProximidadeFrame", acViewHidden
Debug.Print "report:" & strSetSQL
Reports![sreport_fichaProx imidade].R eport.Reco rdSource = Forms![_commonVariables]![ strSetSQL]
DoCmd.OpenReport "fichaProximidadeFrame", acViewPreview
End Sub
where [sreport_fichaProximidade ] is the name of the control of the subreport inside the main report.
1. first it does print a page containing the complete query per record. I have 16 records, so I get 16 compelete pages (!)
2. it does no show the preview - it directly goes to print in a printer :(
3. the control is no recognized...
can you help?
My code is:
Private Sub btn_reportProximidade_Clic
Dim strSetSQL As String
DoCmd.OpenReport "fichaProximidadeFrame", acViewHidden
Debug.Print "report:" & strSetSQL
Reports![sreport_fichaProx
DoCmd.OpenReport "fichaProximidadeFrame", acViewPreview
End Sub
where [sreport_fichaProximidade ] is the name of the control of the subreport inside the main report.
1. first it does print a page containing the complete query per record. I have 16 records, so I get 16 compelete pages (!)
2. it does no show the preview - it directly goes to print in a printer :(
3. the control is no recognized...
can you help?
acViewHidden is not something Access recognizes.
https://msdn.microsoft.com/en-us/library/office/ff195735.aspx
acHidden can be specified as a window mode:
https://msdn.microsoft.com/en-us/library/office/ff195725.aspx
If you want to change the RecordSource for a report and are NOT deploying as an ACCDE, then please refer to the code I gave you to run. If this will be an ACCDE, then change the RecordSource in the OPEN event of the report.
https://msdn.microsoft.com/en-us/library/office/ff195735.aspx
acHidden can be specified as a window mode:
https://msdn.microsoft.com/en-us/library/office/ff195725.aspx
If you want to change the RecordSource for a report and are NOT deploying as an ACCDE, then please refer to the code I gave you to run. If this will be an ACCDE, then change the RecordSource in the OPEN event of the report.
I am so sorry. That was my bad, I got the syntax wrong. As Crystal indicates, the hidden is a window property, not a report property. I have corrected the syntax below.
DoCmd.OpenReport "fichaProximidadeFrame",acViewPreview,,,acHidden
Reports![fichaProximidadeFrame]![sreport_fichaProximidade].Report.RecordSource = Forms![_commonVariables]![strSetSQL]
DoCmd.OpenReport "fichaProximidadeFrame", acViewPreview
ASKER
Thanks for the help!!!!
Have you tried to reverse the order?
Open in new window
I believe the requery is not required in this situatoin (i.e. it should requery on its own when the recordsource is changed)
If this doesn't work, it might be better to open the form hidden first, do the modification, and then change it to visible like below:
Open in new window