Link to home
Start Free TrialLog in
Avatar of Luis5011
Luis5011

asked on

MS Access run-time error 2046

Run-time error '2046':
The command or action 'Output To' isn't available now.

I know this is related to the fact that when my macros run, from a switchboard command, my database window is hidden.  What I don't understand is that I have another database that runs off of a macro that, when a switchboard button is pushed, it runs the macro and all of the commands and saves a number of reports out to a folder and then closes itself.  All the while, the database window is hidden.  I also have some VBA that tells Access where to save the reports and adds the current date to the file name.  I have not problems with this report, yet in my other database, I keep having issues, the most recent this run time error.

Any help or clarification would be appreciated.  
Avatar of Chuck Wood
Chuck Wood
Flag of United States of America image

Try this (from the link below).
http://forums.devarticles.com/microsoft-access-development-49/outputto-isn-t-avaliable-now-11771.html 
-Chuck
' turn the echo off
DoCmd.Echo False
' show the db window
DoCmd.SelectObject acTable, , True
 
' run your code
 
' hide the db window again
Docmd.SelectObject acTable, , True
Docmd.RunCommand acCmdWindowHide
'turn the echo back on
DoCmd.Echo True

Open in new window

Avatar of Luis5011
Luis5011

ASKER

Here's the catch.  Most of my commands are being run through the macro protion of Access.  I only have the save to folder command in VBA.  So, do I set up this VBA code and set up a runcode macro that executes the first part of this code, then at the very end set up another runcode macro to execute the last part?

On a side note, if I were to use the convert macros to VB, would that make things run more efficiently?  Then I could just use one command in a macro to execute the whole thing.  I don't know why, but I'm hesitant to convert it all.  I feel like I'm going to jack things up.
You can copy the code in the snippet into your "output to" VBA code, replacing "' run your code" with your current "output to" code.

If you are comfortable with macros, you can stick with them with occasional references to VBA functions. If you want to play around with pure VBA, you can make a copy of your database, convert the macros to VBA, and see how the code works. You are quite right to be hesitant to do a conversion on your live database.
-Chuck
If you want to post your VBA function, I can show you how to add the code I posted to it.
-Chuck
Chuck, as always, thank you for your help.  Below is the only peice of code I'm running.  The rest is a bunch of openquery, openreport, etc. functions in the macro section of Access.  My preliminary problem was that I was running out of temp disk space to add something like the command below.  But I moved it into another macro that didn't have too many commands, and it started to run, but then I got this run time error.  Unfortunately, I didn't build this database, but I sure as heck inherited all of the issues.  It's very convoluted and why the designer did some of the things she did is beyond me.  It's a good db, just not an easy one to maintain or change.
Function CreateSnapShots_CC()
Dim strPath As String
Dim i As Integer
 
ReDim aryReports(1 To 1)
aryReports(1) = "Daily Discharge CC"
    
    For i = 1 To 1
        strPath = "\\Humana_tree\.CORMKT1_DATA.COR.Area45.Hum\SHARED\Health Services\Daily Census\"
        strPath = strPath & aryReports(i) & ".SNP"
        DoCmd.OutputTo acOutputReport, aryReports(i), acFormatSNP, strPath
    Next i
        
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chuck Wood
Chuck Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You ROCK, Chuck!  Thanks.  Tune in next week...I'm sure I'll find myself in another snag.  Have a great day.
You are welcome. Good luck with your project and you have yourself a great weekend.
-Chuck