• Output using VBA not consistent (2000 SR1)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Output using VBA not consistent (2000 SR1)

    Author
    Topic
    #403852

    Why does the code below work in some databases and not others? Even from week to week in the same database?

    Option Compare Database
    Option Explicit

    Sub OUTPT()
    Dim qdftemp As QueryDef
    Dim a As String
    For Each qdftemp In CurrentDb.QueryDefs
    a = qdftemp.Name
    DoCmd.OutputTo acQuery, a, “MicrosoftExcel(*.xls)”, _
    “C:My DocumentsTESTSTORES” & qdftemp.Name & “.xls”, False, “”
    Debug.Print qdftemp.Name
    Next

    End Sub

    Viewing 3 reply threads
    Author
    Replies
    • #816964

      How does it fail? Do you get an error message, and if so, what does it say?

      Does the code export a few queries and then fail, or does it cause an error immediately?

      Can you discover a pattern in when or where the code fails?

      • #816989

        Compile error:
        User-defined type not defined.

        It fails everytime before it runs anything …highlighting the dim statement.

        The frustrating part is that I copied this from one database I’m using (where it works every week). Plus when I ran this two weeks ago in this one & it worked.

        • #816991

          In the Visual Basic Editor, select Tools | References.
          Locate Microsoft DAO 3.6 Object Library, tick the corresponding check box and click OK.
          You will have to do this for every database containing this code. In Access 2000 and up, there is no default reference to the DAO library (there was in Access 97 and before.)

          • #816999

            THANK YOU!!! Another question… I had this working 2 weeks ago by adding this reference. Is there something I need to do to the module or the database prior to closing to it so that it’s preserved?

            • #817001

              No, a reference, once set, should stay set until you clear it. I can’t explain why the reference should have become unset.

            • #817002

              No, a reference, once set, should stay set until you clear it. I can’t explain why the reference should have become unset.

          • #817000

            THANK YOU!!! Another question… I had this working 2 weeks ago by adding this reference. Is there something I need to do to the module or the database prior to closing to it so that it’s preserved?

        • #816992

          In the Visual Basic Editor, select Tools | References.
          Locate Microsoft DAO 3.6 Object Library, tick the corresponding check box and click OK.
          You will have to do this for every database containing this code. In Access 2000 and up, there is no default reference to the DAO library (there was in Access 97 and before.)

      • #816990

        Compile error:
        User-defined type not defined.

        It fails everytime before it runs anything …highlighting the dim statement.

        The frustrating part is that I copied this from one database I’m using (where it works every week). Plus when I ran this two weeks ago in this one & it worked.

    • #816965

      How does it fail? Do you get an error message, and if so, what does it say?

      Does the code export a few queries and then fail, or does it cause an error immediately?

      Can you discover a pattern in when or where the code fails?

    • #816969

      You can output only a non-action query to Excel. Since Append, Update and MakeTable queries do not return rows, there is nothing there to export. Could that be your problem?

    • #816970

      You can output only a non-action query to Excel. Since Append, Update and MakeTable queries do not return rows, there is nothing there to export. Could that be your problem?

    Viewing 3 reply threads
    Reply To: Output using VBA not consistent (2000 SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: