what am i missing?

mikela

Registered User.
Local time
Today, 09:11
Joined
Nov 23, 2007
Messages
70
Hey!

I need to delete all the controls from a report dynamically, and I've tried the following:

DoCmd.OpenReport "myreport", acViewDesign
Set rpt = Reports![myreport]

Dim c As Control
For Each c In rpt
rpt.DeleteReportControl rpt.name, c.name
Next


and it won't work... the following error appears:

Run-time error: 2465
application-defined or object defined error.

Any idea what i am missing?
 
There may be more but the first thing for sure is

For Each c In rpt

You need

For Each c In rpt.Controls
 
Hello!

Thanks for your reply, i've tried and still not working. The thing is that it deletes some controls, but not all of them, so i get an error... The code right now is the following:

Dim rpt As Report
DoCmd.OpenReport "test4", acViewDesign
Set rpt = Reports![test4]

Dim c As Control
For Each c In rpt.Controls
DeleteReportControl rpt.name, c.name
Next


Any suggeriment??

Thanks
 
Just out of curiosity - what is the reason behind this? Why would you need to delete the controls on a report? Frankly it doesn't make sense to me, but maybe you have a reason I haven't thought of. The reason I ask is that maybe there's some alternative thing you can do that you haven't thought of, depending on what you are trying to accomplish.
 
Just out of curiosity - what is the reason behind this? Why would you need to delete the controls on a report? Frankly it doesn't make sense to me, but maybe you have a reason I haven't thought of. The reason I ask is that maybe there's some alternative thing you can do that you haven't thought of, depending on what you are trying to accomplish.

yeah why not click on the report and press the delete button? quick and easy
 
well...

I need to create a report that the select depends on what the user introduces... no way to figure out how to do it, i found a solution that was create a query everytime, and create the report by code. More accurate, the report is already created, but I create the data displayed by code. The problem is that everytime the user changes the select statment, the record of the previous report appears as a pop up, waiting for the user to introduce the data... So I need to delete all the controls from the report before creating new ones in order to avoid the pop up screen...

Does it make sense??? That was the only solution I found...

But I've got the solution already! It was creating a function that checks that the controls in the report=0, if not -> deleteControls.

Because the problem was that the for each statment didn't delete all the records, but some...

Strange... :confused:
 
well...

I need to create a report that the select depends on what the user introduces.
What are they "introducing?" How are they doing it? Are they selecting the fields from a selection? Do you have this set up as kind of a report generation wizard?

Code:
The problem is that everytime the user changes the select statment, the record of the previous report appears as a pop up, waiting for the user to introduce the data...

I use lots of reports with different SQL statements and haven't had that problem, but then again you have to close the report and the reopen it, you can't set the SQL recordsource for a report that is already open.



So I need to delete all the controls from the report before creating new ones in order to avoid the pop up screen...
I don't think you do if you close the report before setting the new SQL and reopening. But, if the fields are different then you would need to also set the controls' recordsources upon opening as well.

Because the problem was that the for each statment didn't delete all the records, but some...
 

Users who are viewing this thread

Back
Top Bottom