Solved Save Form As Report using VBA (1 Viewer)

andreaerdna

New member
Local time
Today, 21:59
Joined
Jul 4, 2020
Messages
3
In MS Access it's possible to convert a Form to a Report using the "Save Object As" functionality (Office Button -> Save As -> Save Object As "Save the current database object as a new object").

I'd like to have the same functionality using VBA but it seems to me that none of the following relevant DoCmd methods are suitable CopyObject, OutputTo, Save, TransferDatabase.

I was unable to find any useful information, except a blog post in which a code sample is provided using the SendKeys statement, but it seems not working.

Any advice on how to proceed or to fix the SendKeys statement string in the that blog post?
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:59
Joined
Sep 21, 2011
Messages
14,470
Cross posted with reply, presumably not to the o/p's liking.?

 

andreaerdna

New member
Local time
Today, 21:59
Joined
Jul 4, 2020
Messages
3
Probably I thought there was someone more experienced in this forum than on stackoverflow.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:59
Joined
May 21, 2018
Messages
8,607
Demo. I can do
acCmdSaveas but not acCmdSaveAsReport. But this will save the form as a report.
 

Attachments

  • MajP_Savereport.zip
    61.3 KB · Views: 145

andreaerdna

New member
Local time
Today, 21:59
Joined
Jul 4, 2020
Messages
3
Thank you very much @MajP and @theDBguy !

@MajP your is a step forward!

Now I see the light!

I'd like to do it programmatically, for a given Form, without the need of the user (me) intervention (like inserting the name of the Report to be saved or selecting "Report" from the drop down list in the "Save As" window).

So, thanks to your tips I managed to obtain a working (for me) code (but also using SendKeys):

Code:
strFormName = "formname"
strReportName = "reportname"
DoCmd.SelectObject acForm, strFormName, True
SendKeys strReportName & "~"
RunCommand acCmdSaveAsReport

This however will not solve another problem: do the same thing, but in an external database.

Is there a way to avoid to:
- import the Form from the external db into the current db
- save the form as a report applying the above procedure
- delete the imported Form from the current db
- export the report to the external db
- delete the report from the current db?

Andrea
 

Users who are viewing this thread

Top Bottom