benjamin.grimm
Registered User.
- Local time
- Yesterday, 19:11
- Joined
- Sep 3, 2013
- Messages
- 125
hello togehter,
the access database is about contracts.
Each contract has an ID.
So starting from ID1 to ID250.
Right now i export in via VBA to excel.
I have to create before in the excel the 250 tables.
If the ID10 is not existing anymore i still have the table 10 left and then i have to delete this table.
How can i change that?
greetz benjamin
the access database is about contracts.
Each contract has an ID.
So starting from ID1 to ID250.
Right now i export in via VBA to excel.
I have to create before in the excel the 250 tables.
If the ID10 is not existing anymore i still have the table 10 left and then i have to delete this table.
How can i change that?
Code:
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_laufend 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("E:\SuW\S-Laufwerk\Tabellen\Auswertung-laufend.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_laufend WHERE SuWID = " & rstID.Fields("SuWID"))
xlSheet.Range("A6").CopyFromRecordset rstGr
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
greetz benjamin