Unanswered: OutputTo command or action isnt available now
I have been having some problems with the DoCmd.OutputTo method with Access 2002 and there seem to be users with similar problems and various reasons/fixes available but they are all a bit sketchy. I thought I'd post this to hopefully help anyone else who experiences the same problem.
I was getting the runtime error 2046 Command or Action 'DoCmd.OutputTo' isn't available now when using the following code:
(where sFormName and sFileName are passed from the class module behind the calling form).
The error seemed to be sporadic at first and some posts mention having the database window hidden on startup may cause this problem. This works but is no good if you want to compile your database and don't want the db window on show.
I found that a) having the object open and b) using the following code just before you export does the trick without the need to show the database window on startup:
Further to my last message, if you are using DoCmd.OutputTo with dynamic SQL, e.g. you need to export a parameterised stored procedure, you can't open the stored procedure first so you need to create or use a dummy procedure instead. This can then be opened and selected using:
I noticed that the error occurs when you have a form in pop up mode and the report is on a different mode. By changing the forms to pop up mode = Yes to match the from from where I was executing the "output to" the error went away