1 Reply Latest reply: May 15, 2014 9:57 AM by computer33 _ RSS

    VBA works in step mode but not when Run

    computer33 _

      This is somewhat strange but if I step through my code it all works flawlessly.  However, when I run it in its entirety the tables are not created?

       

      Here is my Code. [font="courier"]Private Sub Monarch_Table()

      Dim strMyPath As String

      Dim strMyReport As String

      Dim strMyModel As String

      Dim strMyModel2 As String

      Dim strExportTable As String

      Dim strExportTable2 As String

      Dim strMyLog As String

       

      strMyPath = "C:Documents and SettingswocaMy DocumentsCarlos ImageMonarch ExportsPDF"

      strMyReport = strMyPath & "CPS.pdf"

      strMyModel = strMyPath & "PDF_BUILD_3_A.xmod"

      strMyModel2 = strMyPath & "PDF_BUILD_3_B.xmod"

      strExportTable = strMyPath & "CPS.mdb"

      strExportTable2 = strMyPath & "CPS_TU.mdb"

      strMyLog = strMyPath & "Log.log"

       

      'Delete Old Files

      On Error Resume Next

      Kill strExportTable

      Kill strExportTable2

      On Error GoTo 0

       

          Dim MonarchObj As Object

          Dim openfile, openmod, t As Boolean

          'If Monarch is currently active GetObject will use Monarch. If it is not use the CreateObject() to

          'open another copy of Monarch.

          Set MonarchObj = GetObject("", "Monarch32")

          If MonarchObj Is Nothing Then

              Set MonarchObj = CreateObject("Monarch32")

          End If

           

          t = MonarchObj.SetLogFile(strMyLog, False)

          openfile = MonarchObj.SetReportFile(strMyReport, False)

          If openfile = True Then

              openmod = MonarchObj.SetModelFile(strMyModel)

              If openmod = True Then

                  'Set filter for each frame and export to Excel

                  'MonarchObj.CurrentFilter = "Fandangos records"

                  ExportData = MonarchObj.JetExportTable(strExportTable, "Untitled", 0)

                  'MonarchObj.CurrentFilter = "No Returns"

                  'MonarchObj.ExportTable ("C:Program FilesMonarchExportNo Returns.xls")

                  'If ExportData = True Then Debug.Print "suceess"

                  'If ExportData = False Then Debug.Print "failed"

              End If

          End If

          MonarchObj.CloseAllDocuments

          openfile = MonarchObj.SetReportFile(strMyReport, False)

          If openfile = True Then

              openmod = MonarchObj.SetModelFile(strMyModel2)

              If openmod = True Then

                  'Set filter for each frame and export to Excel

                  'MonarchObj.CurrentFilter = "Fandangos records"

                  ExportData2 = MonarchObj.JetExportTable(strExportTable2, "TU", 0)

                  'MonarchObj.CurrentFilter = "No Returns"

                  'MonarchObj.ExportTable ("C:Program FilesMonarchExportNo Returns.xls")

              End If

          End If

          MonarchObj.CloseAllDocuments

          MonarchObj.Exit

          If ExportData = True And ExportData2 = True Then

              DoCmd.RunMacro "PDF"

          Else

              MsgBox "Tables were not created", vbCritical, "Could Not Create Tables"

          End If

      End Sub[/font][/quote]