[AccessD] DoCmd.OutputTo Bug in Library in Access 2007

Dan Waters df.waters at comcast.net
Tue Mar 1 07:50:42 CST 2011


A couple of weeks ago someone posted a problem with DoCmd.OutputTo, and a
few days ago I came across a related bug introduced in Access 2007.  I don't
have Access 2010 - perhaps someone can see if the problem still exists
there.

If you have a procedure in a referenced Library file that outputs an object,
where the object is stored in the Main file, you'll get an error.  This
worked fine in Access 2003, but fails in Access 2007.  The help files in
both versions say that Access looks in the Library first, then in the Main
file.

This is a workaround that I've tested.  As an example, this procedure can be
called by either the Library or the Main files, and determines which file
the object is in.  If the object is in the Main file, then the procedure
uses CurrentProject.Application.DoCmd.OutputTo, which bypasses the bug.

HTH!
Dan

'--------------------------------------

Public Sub LibraryOutput(intObjectType As Integer, stgObjectName As String,
varOutputFormat As Variant, stgAccessObjectPath As String)

    '-- Purpose:  This will take an Access Object for output from a
referenced Library file. _
                  If the object is in the CurrentProject, then
DoCmd.OutputTo won't see that object _
                  due to a bug introduced in Access 2007. _
                  However, using CurrentProject.Application.DoCmd.OutputTo
in the library will work.
                  
    Dim aob As AccessObject
    Dim blnReportInLibrary As Boolean
            
    '-- Is this report in the Library?
    For Each aob In CodeProject.AllReports
        If aob.Name = stgObjectName Then
            blnReportInLibrary = True
        End If
    Next aob

    '-- Output report from the file it's in
    If blnReportInLibrary = True Then
        DoCmd.OutputTo intObjectType, stgObjectName, varOutputFormat,
stgAccessObjectPath
    Else
        CurrentProject.Application.DoCmd.OutputTo intObjectType,
stgObjectName, varOutputFormat, stgAccessObjectPath
    End If

End Sub

'--------------------------------------







More information about the AccessD mailing list