Dim rsGroup As DAO.Recordset
Dim ColumnName As String, AbttName As String, DRName As String, myPath As String
myPath = "……………"
Set rsGroup = CurrentDb.OpenRecordset("SELECT DISTINCT Abtt, Ciid, Fill, DT, AT, AT, CS FROM Tab_produzione_report_PDF", _
dbOpenDynaset)
Do While Not rsGroup.EOF
ColumnName = rsGroup!Ciid
AbttName = rsGroup!Abtt
FillName = rsGroup!Filliale
DTName = rsGroup!DT
ATName = rsGroup!AT
AT = rsGroup!AT
CS = rsGroup!CS
If rsGroup!AT = -1 And rsGroup!CS = -1 Then
DoCmd.OpenReport "Master_operativita_new_DEF_1", acViewPreview, , "[CodiceCiid]='" & ColumnName & "' And [CodiceAbtt]='" & AbttName & "'"
DoCmd.OutputTo acOutputReport, "Master_operativita_new_DEF_1", acFormatPDF, _
myPath & AbttName & "_" & ColumnName & "_" & DTName & "_" & ATName & "_Report_AT-CS" & ".pdf", False
DoCmd.Close acReport, "Master_operativita_new_DEF_1"
ElseIf rsGroup!AT = 0 And rsGroup!CS = -1 Then
DoCmd.OpenReport "Master_operativita_new_DEF_1_CS", acViewPreview, , "[CodiceCiid]='" & ColumnName & "' And [CodiceAbtt]='" & AbttName & "'"
DoCmd.OutputTo acOutputReport, "Master_operativita_new_DEF_1_CS", acFormatPDF, _
myPath & AbttName & "_" & ColumnName & "_" & DTName & "_" & ATName & "_Report_AT-CS" & ".pdf", False
DoCmd.Close acReport, "Master_operativita_new_DEF_1_CS"
ElseIf rsGroup!AT = -1 And rsGroup!CS = 0 Then
DoCmd.OpenReport "Master_operativita_new_DEF_1_AT", acViewPreview, , "[CodiceCiid]='" & ColumnName & "' And [CodiceAbtt]='" & AbttName & "'"
DoCmd.OutputTo acOutputReport, "Master_operativita_new_DEF_1_AT", acFormatPDF, _
myPath & AbttName & "_" & ColumnName & "_" & DTName & "_" & ATName & "_Report_AT-CS" & ".pdf", False
DoCmd.Close acReport, "Master_operativita_new_DEF_1_AT"
End If
rsGroup.MoveNext
Loop
End Sub