Full Version: Adding objects dynamically to existing report
UtterAccess Forums > Microsoft® Access > Access Forms
pbutler
I have a report called Student_Roster that I'd like to add different objects to, depending on what button from a menu called it. On tab A, button A will print Student_Roster, filterered by A, and will print fields A, B, C. On tab B, button B will print Student_Roster, filtered by B, and will print fields X, Y, Z.
) I didn't want to create the report completely dynamically, but rather copy the existing report and add different objects to the report, based on which "button" is calling the program.
cReportName = CreateTempFile() 'creates temporary file name
DoCmd.CopyObject , cReportName, acReport, "Student_Roster"
DoCmd.OpenReport cReportName, acViewDesign
...add objects
DoCmd.OpenReport cReportName, acViewPreview
' DoCmd.Close 'acReport, cReportName
' DoCmd.DeleteObject acReport, cReportName
I'm finding that if DoCmd.Close is uncommented, then the report doesn't open, since it goes from OpenReport to Close. If DoCmd.Close is commented, then I get an error that I can't delete the report while it's open.
1a) Should I just add objects to Student_Roster itself and not copy to a temporary report that will need to be deleted afterwards?
2) Once the report comes up in Preview, I get the message "Do you want to save changes to abde1234? " That's the temporary report that got created. How do I avoid getting that message? If I do as suggested in 1a), then I definitely can't have the user save the report they just ran.
freakazeud
Hi,
I think you are going about this the completely wrong way. You should need to create and delete temporary reports to be able to display what you want. Normally you would create a query that filters everything as you want even if the criteria comes from the user selecting it on a form. Then a report would be based on that to show what the query returned. Programmatically creating/deleting objects/controls...will lead to bloating as well as corruption issues and also run into other problems like control/object limits you can have within one MDB file.
HTH
Good luck
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.