Share via

DoCmd.OutputTo error

Anonymous
2015-04-09T10:50:10+00:00

Hi

I hope someone can help me as I am at a loose end.

I have some code that has been working perfectly fine in Access 2007 but now I have moved to 2010 I am getting the following error:

The command or Action 'OutputTo' isn't available now

The code I have looks fine:

If Len(Dir("c:\Temp", vbDirectory)) = 0 Then

       MkDir "c:\Temp"

End If

    DoCmd.OutputTo acOutputReport, "Pallet Label", acFormatPDF, "C:\Temp\PalletLabel.pdf", False

    DoCmd.OutputTo acOutputQuery, "OutsideStorageDespatchFormXLS", acFormatXLS, "C:\Temp\OutsideStorageDespatchFormXLS.xls", False

Any ideas?

Cheers

Aaron

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-04-09T14:29:33+00:00

Hi,

so have you tried to open and close the objects as I've described it?

...

DoCmd.OpenReport "Pallet Label", acViewPreview

DoCmd.OpenQuery "OutsideStorageDespatchFormXLS"

...

    DoCmd.OutputTo acOutputReport, "Pallet Label", acFormatPDF, "C:\Temp\PalletLabel.pdf", False

    DoCmd.OutputTo acOutputQuery, "OutsideStorageDespatchFormXLS", acFormatXLS, "C:\Temp\OutsideStorageDespatchFormXLS.xls", False

DoCmd.Close acReport, "Pallet Label"

DoCmd.Close acQuery, "OutsideStorageDespatchFormXLS"

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2015-04-09T15:35:48+00:00

    Hi

    Sorry.  I didn't know you could do a docmd.OpenQuery on a select query.

    I have done this and it has started working again.

    Bit strange.  Must have been some functionality issue between 2007 and 2010.

    Thanks for your help.

    It has been much appreciated.

    Aaron

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-04-09T13:55:52+00:00

    Thanks for replying Karl.

    Basically on a form I press a button which closes the form and then perfoms the tasks.

    See full code below:

    Private Sub Command37_Click()

    Dim objMsg As MailItem

    ' Process Raw Material Delivery into SUUS

        DoCmd.SetWarnings (WarningsOff)

        DoCmd.RunCommand acCmdSaveRecord

        DoCmd.Close acForm, "Enter Pallet Qty"

        DoCmd.OpenQuery "UpdateRelationFieldSDTT"

        DoCmd.OpenQuery "ApdTotalsToMaterialDeliveries"

        DoCmd.OpenQuery "MakeTableDeliveryToSR"

        DoCmd.OpenQuery "UpdateDeliverySR"

        DoCmd.OpenQuery "ApdNewPalletsToBIM_Suus"

        DoCmd.Close acForm, "Raw Material Switchboard"

    '    DoCmd.OpenReport "Pallet Label", acViewNormal, "", "", acNormal

    ' Create Temporary File

    If Len(Dir("c:\Temp", vbDirectory)) = 0 Then

           MkDir "c:\Temp"

    End If

        DoCmd.OutputTo acOutputReport, "Pallet Label", acFormatPDF, "C:\Temp\PalletLabel.pdf", False

        DoCmd.OutputTo acOutputQuery, "OutsideStorageDespatchFormXLS", acFormatXLS, "C:\Temp\OutsideStorageDespatchFormXLS.xls", False

    I tried commenting out the pdf line but this had the same effect.

    The folder Temp is already in the C:\ root.  It was working but has suddenly stopped.

    I can open the report but the second one is query which I want to put into Excel.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-04-09T13:06:26+00:00

    Hi,

    where and when do you try to execute the code? Which event, control, object?

    Try to execute just 1 of the OutputTo actions. Does it work for either the PDF or XLS line only?

    Try to use a preexisting directory instead of c:\Temp".

    Sometimes (in the latest Access versions) the only resolution to this error is to open the objects (here with OpenReport and OpenQuery), then execute OutputTo and then close the objects. If that does the trick then try if it still works if you open the objects with the hidden argument set.

    Was this answer helpful?

    0 comments No comments