benjamin.grimm
Registered User.
- Local time
- Yesterday, 23:12
- Joined
- Sep 3, 2013
- Messages
- 125
hello guys,
i Export data by the following code.
It works actually but when i go back to Access i get the following error message
runntime error 424, object is necessary.
i Export data by the following code.
It works actually but when i go back to Access i get the following error message
runntime error 424, object is necessary.
Code:
Private Sub Befehl1_Click()
Dim xlApp As Object 'Excel.Application
Dim xlBook As Object 'Excel.Workbook
Dim xlSheet As Object 'Excel.Worksheet
Dim rstID As DAO.Recordset, tmpStr As String
Dim rstGr As DAO.Recordset, strSQL As String
strSQL = "SELECT SuWID FROM Abfrage_alles GROUP BY SuWID;"
Set rstID = CurrentDb.OpenRecordset(strSQL)
If rstID.RecordCount > 0 Then
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("C:\Users\GRIMBEN\Desktop\SuW\S-Laufwerk\Tabellen\Try-alle.xlsm")
Do While Not rstID.EOF
Set xlSheet = xlBook.Sheets("Tabelle " & rstID.Fields("SuWID"))
xlSheet.Name = "ID" & rstID.Fields("SuWID")
Set rstGr = CurrentDb.OpenRecordset("SELECT SAP, Geris, Pauschale, SuWID, Jahr_Y, BT_Name, SAP_Nummer, Vertragsbeginn, Vertragsende FROM Abfrage_alles WHERE SuWID = " & rstID.Fields("SuWID"))
[COLOR=yellow] xlSheet.Range("A6").CopyFromRecordset rstGr
[/COLOR] rstGr.Close
rstID.MoveNext
Loop
Else
MsgBox "No information to export", vbInformation, "No data exported"
End If
rstID.Close
Set rstID = Nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub