Option Compare Database
Const sSpeicherpfad As String = "h:\Kündigungsmakro\Abteilungsexport"
Const sSQLallAbt As String = "SELECT TDaVertraege.* FROM TDaVertraege INNER JOIN ADAExport2Abt ON [TDaVertraege].[DaID]=[ADAExport2Abt].[DaID] "
Private Sub btnClosefrm_Click()
On Error Resume Next
DoCmd.Close
End Sub
Sub exportAll()
On Error GoTo ErrExportAll
Dim DB As DAO.Database
Dim rs As DAO.Recordset
Set DB = CurrentDb()
Set rs = DB.OpenRecordset("Select * from TAbAbteilungVersand")
rs.MoveFirst
rs.MoveLast
erg = rs.RecordCount
If erg > 0 Then
rs.MoveFirst
Do Until rs.EOF
exportAbtDaten rs.Fields("AbID") '!
rs.MoveNext
Loop
End If
Exit Sub
ErrExportAll:
End Sub
Sub exportAbtDaten(sAbtGr As String)
On Error Resume Next
Dim DB As Database
Dim qdfNeu As QueryDef
Set DB = CurrentDb()
DB.QueryDefs.Delete "TempExport2Abt"
'Pause 0.2
Set qdfNeu = DB.CreateQueryDef("TempExport2Abt", sSQLallAbt & " WHERE [TDaVertraege].[DaAbteilung] In (select AaAbteilung from TAaAbteilungen where AaVersandID = '" & sAbtGr & "') ")
'Pause 0.3
nDcount = DCount("[DaID]", "TempExport2Abt")
sid = DFirst("[AbID]", "TAbAbteilungVersand", "[AbID] = '" & sAbtGr & "'")
If nDcount > 0 Then
sAN = DFirst("[AbAN]", "TAbAbteilungVersand", "[AbID] = '" & sAbtGr & "'")
sCC = DFirst("[AbCC]", "TAbAbteilungVersand", "[AbID] = '" & sAbtGr & "'")
sBetreff = DFirst("[AbBetreff]", "TAbAbteilungVersand", "[AbID] = '" & sAbtGr & "'") & " " & Format(Date, "dd.MM.yyyy")
sNachricht = DFirst("[AbNachricht]", "TAbAbteilungVersand", "[AbID] = '" & sAbtGr & "'")
Dim GetSaveFile As String
'DoCmd.SetWarnings False
strfilter = "Alle Dateien" & Chr$(0) & "*.*" & Chr$(0) & Chr$(0)
defFilename = "Ablauf_" & sid & Format(Date, "_yyyy_MM_dd") & ".xls"
GetSaveFile = XGetSaveFile("Datei speichern", strfilter, 4, "xls", sSpeicherpfad, defFilename)
If GetSaveFile <> "" Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4, "TempExport2Abt", GetSaveFile, True
End If
On Error GoTo ErrexportAbtDaten
If sid = "6KR01" Then
KR01
End If
If sid = "6KR02" Then
KR02
End If
If sid = "6KR03" Then
KR03
End If
If sid = "6KR04" Then
KR04
End If
If sid = "6LA03" Then
LA
End If
If sid = "8GF02" Then
GF02
End If
If sid = "8GF03" Then
GF03
End If
If sid = "8OE03" Then
OE
End If
' DoCmd.SendObject acSendQuery, "TempExport2Abt", acFormatXLS, sAN, sCC, "simon.Lindner@vkb.de", sBetreff, sNachricht, False
erg = MsgBox("Die Daten wurden auf die Festplatte gespeichert unter " & GetSaveFile & Chr(10) & Chr(13) & "Sollen die Daten als gesendet makiert werden?", vbYesNo + vbQuestion, "VKB Kündigungsmakro")
If erg = vbYes Then
DoCmd.OpenQuery "ADaExport2Abtdone"
End If
'DoCmd.SetWarnings True
subfrmExport2AbtSubfrm.Requery
Else
MsgBox "Keine Daten für die Gruppe " & sid & " vorhanden"
End If
Exit Sub
ErrexportAbtDaten:
MsgBox Err.Description
Resume Next
End Sub
6KRxx sind dann nur noch die sendobjects!