von WSO » Sa, 12.07.2014 12:13
			
			
			Hallo Zusammen,
Ich vervende das oft zitierte Makro aus dem Base-Handbuch "ExportData" unter LO 4.2 mit Win 7 und Linux.
Das Makro bringt einen Fehler: (Message:
 Table not found in statement [SELECT * FROM "abfRec"].), 
wenn ich es fuer eine 
Abfrage aufrufe.
Bei Export einer 
Tabelle oder View geht es einwandfrei.
Weiss jemand woran das liegt?
Vielen Dank vorab,
WSO
Code: Alles auswählen
 Sub ExportRechnung (oEvent AS OBJECT)
       REM Speicherpfad
       sPath = "D:"
       REM Dateiname
       sTitle = "Datenexport vom " & Date & ".ods"
       REM Name der Abfrage, Tabelle oder SQL-Statement
       'sQueryName = "Screening_Tabelle_1"
       'sQueryName = "Abfrage_Screening_Tabelle_1"
       sQueryName = "SELECT * FROM ""abfRec"""
      'sQueryName = "SELECT * FROM ""Abfrage_Screening_Tabelle_1"""
         
       sURL = ConvertToURL(sPath & "/" & sTitle)
       If FileExists(sURL) Then
          i = MsgBox(">" & sTitle & "<" & Chr(13) & "Datei existiert bereits." & _
                      Chr(13) & Chr(13) & "Überschreiben?",52,"Hinweis")
          If i <> 6 Then
             Exit Sub
          End If
       End If
       oCon = thisComponent.Parent.CurrentController.ActiveConnection
       If oCon.Tables.hasByName(sQueryName) Then
          oPrepStatement = oCon.prepareCommand(sQueryName,0)
       ElseIf oCon.Queries.hasByName(sQueryName) Then
          oPrepStatement = oCon.prepareCommand(sQueryName,1)
       Else
          oPrepStatement = oCon.prepareCommand(sQueryName,2)
       End If
       oResult = oPrepStatement.executeQuery
       aColumns = oPrepStatement.Columns.ElementNames
       oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank", 0, Array())
       oSheet = oDoc.Sheets(0)
       nColumnCount = UBound(aColumns)
       Dim aLine(nColumnCount)
       Dim aData(0)
       aData(0) = aColumns
       nUpperBoundary = 0
       Do While oResult.Next
          nUpperBoundary = UBound(aData)+1
          ReDim Preserve aData(nUpperBoundary)
          ReDim aLine(nColumnCount)
          For i = 0 To nColumnCount
             aLine(i) = oResult.getString(i+1)
          Next i
          aData(nUpperBoundary) = aLine
       Loop
       oRange = oSheet.getCellRangeByPosition(0,0,nColumnCount,nUpperBoundary)
       oRange.setDataArray(aData)
       Dim args(0) as New com.sun.star.beans.PropertyValue
       Dim Dateiname
       args(0).Name = "Overwrite"
       args(0).Value = True
    'Dateiname = GetVariable(oDoc,"Screening_Tabelle_1")
    'URL = "C:\Users\user\Documents\"
    'sURL = ConvertToURL(URL + Dateiname)
    'oDoc.storeAsURL(sURL, arg())
    End Sub
 
			
			
							Hallo Zusammen,
Ich vervende das oft zitierte Makro aus dem Base-Handbuch "ExportData" unter LO 4.2 mit Win 7 und Linux.
Das Makro bringt einen Fehler: (Message:[color=#0000FF] Table not found in statement [SELECT * FROM "abfRec"].[/color]), 
wenn ich es fuer eine [color=#BF0000]Abfrage[/color] aufrufe.
Bei Export einer [color=#BF0000]Tabelle oder View[/color] geht es einwandfrei.
Weiss jemand woran das liegt?
Vielen Dank vorab,
WSO
[code]
 Sub ExportRechnung (oEvent AS OBJECT)
       REM Speicherpfad
       sPath = "D:"
       REM Dateiname
       sTitle = "Datenexport vom " & Date & ".ods"
       REM Name der Abfrage, Tabelle oder SQL-Statement
       'sQueryName = "Screening_Tabelle_1"
       'sQueryName = "Abfrage_Screening_Tabelle_1"
       sQueryName = "SELECT * FROM ""abfRec"""
      'sQueryName = "SELECT * FROM ""Abfrage_Screening_Tabelle_1"""
         
       sURL = ConvertToURL(sPath & "/" & sTitle)
       If FileExists(sURL) Then
          i = MsgBox(">" & sTitle & "<" & Chr(13) & "Datei existiert bereits." & _
                      Chr(13) & Chr(13) & "Überschreiben?",52,"Hinweis")
          If i <> 6 Then
             Exit Sub
          End If
       End If
       oCon = thisComponent.Parent.CurrentController.ActiveConnection
       If oCon.Tables.hasByName(sQueryName) Then
          oPrepStatement = oCon.prepareCommand(sQueryName,0)
       ElseIf oCon.Queries.hasByName(sQueryName) Then
          oPrepStatement = oCon.prepareCommand(sQueryName,1)
       Else
          oPrepStatement = oCon.prepareCommand(sQueryName,2)
       End If
       oResult = oPrepStatement.executeQuery
       aColumns = oPrepStatement.Columns.ElementNames
       oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank", 0, Array())
       oSheet = oDoc.Sheets(0)
       nColumnCount = UBound(aColumns)
       Dim aLine(nColumnCount)
       Dim aData(0)
       aData(0) = aColumns
       nUpperBoundary = 0
       Do While oResult.Next
          nUpperBoundary = UBound(aData)+1
          ReDim Preserve aData(nUpperBoundary)
          ReDim aLine(nColumnCount)
          For i = 0 To nColumnCount
             aLine(i) = oResult.getString(i+1)
          Next i
          aData(nUpperBoundary) = aLine
       Loop
       oRange = oSheet.getCellRangeByPosition(0,0,nColumnCount,nUpperBoundary)
       oRange.setDataArray(aData)
       Dim args(0) as New com.sun.star.beans.PropertyValue
       Dim Dateiname
       args(0).Name = "Overwrite"
       args(0).Value = True
    'Dateiname = GetVariable(oDoc,"Screening_Tabelle_1")
    'URL = "C:\Users\user\Documents\"
    'sURL = ConvertToURL(URL + Dateiname)
    'oDoc.storeAsURL(sURL, arg())
    End Sub
[/code]