Public Function StampaApplicazioniUtente(CUtente As Integer) As Boolean
' Viene Eseguita la stampa delle Applicazioni rilasciate all'utente
Dim Strsql As String
Dim rs1 As ADODB.Recordset
Dim Localita As String
Dim DataRit As Date
Dim NrecTot As Integer
Dim nrec As Integer
Dim NrecfromPage As Integer
Dim NPage As Integer
Dim NRigaStart As Integer
Dim Rigaend As Integer
Dim Maxrec As Integer
Dim CdcSave As Integer
Dim Miofoglio As String
Dim CStato As String
' oggetti excel
Dim xlsApp As Object
Dim xlsWB1 As Object
Dim xlsWS1 As Object
StampaApplicazioniUtente = False
Miofoglio = "User"
' apro il file excel esistente per gestire la stampa
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False
Set xlsWB1 = xlsApp.Workbooks.Open(App.Path & "\Dati\Applicazioni_Prt.xls")
Set xlsWS1 = xlsWB1.Worksheets(Miofoglio)
xlsWS1.Select
' Operatore
Strsql = "SELECT AnaDip.Matricola_Dip, AnaDip.Cognome_Dip, AnaDip.Nome_Dip " & _
" FROM AnaDip " & _
" WHERE (((AnaDip.Matricola_Dip)=" & UserLogged & "))"
Set rs1 = conn.Execute(Strsql)
If Not rs1.EOF Then
xlsWS1.Cells(7, 1) = "Operatore: " & rs1("Cognome_Dip") & " " & rs1("Nome_Dip")
Else
xlsWS1.Cells(7, 1) = "Operatore: " & UserLogged & " --- Inesistente ---"
End If
CStato = "G" ' Applicazioni totali
xlsWS1.Cells(4, 9) = TotaliApplUser(CStato, CUtente)
CStato = "A" ' Applicazioni totali
xlsWS1.Cells(5, 9) = TotaliApplUser(CStato, CUtente)
CStato = "E" ' Applicazioni totali
xlsWS1.Cells(6, 9) = TotaliApplUser(CStato, CUtente)
' Utente
Strsql = "SELECT PDL.UtenteActual, AnaDip.Cognome_Dip, AnaDip.Nome_Dip, AnaDip.User_Id_Dip, CDC.D_CDC, FILIALI.DENOMINAZIONE,Anadip.C_Mansione, T_Mansione.D_Mansione " & _
" FROM (FILIALI INNER JOIN ((PDL INNER JOIN AnaDip ON PDL.UtenteActual = AnaDip.Matricola_Dip) INNER JOIN CDC ON PDL.CDC = CDC.C_CDC) ON FILIALI.Cod_fil = CDC.FILIALE_CDC) INNER JOIN T_Mansione ON AnaDip.C_Mansione = T_Mansione.C_Mansione " & _
" WHERE (((PDL.UtenteActual)=" & CUtente & "))"
Set rs1 = conn.Execute(Strsql)
If Not rs1.EOF Then
xlsWS1.Cells(4, 3) = rs1("Cognome_Dip") & " " & rs1("Nome_Dip")
xlsWS1.Cells(5, 3) = rs1("D_CDC")
xlsWS1.Cells(6, 3) = rs1("DENOMINAZIONE")
xlsWS1.Cells(4, 1) = "User Id: " & rs1("User_Id_Dip")
xlsWS1.Cells(4, 4) = rs1("D_Mansione")
xlsWS1.Cells(4, 4).Select
Select Case rs1("C_Mansione")
Case 0
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Grassetto Corsivo"
.Size = 12
.ColorIndex = 3
End With
Case Else
With Selection.Font
.Name = "Times New Roman"
.FontStyle = "Grassetto"
.Size = 12
.ColorIndex = 0
End With
End Select
Else
xlsWS1.Cells(4, 3) = "Utente: " & txt1k & " --- Inesistente ---"
xlsWS1.Cells(5, 3) = ""
xlsWS1.Cells(6, 3) = ""
xlsWS1.Cells(4, 1) = " "
xlsWS1.Cells(4, 4) = " "
MsgBox "Utente inesistente" & vbCrLf & _
" Stampa non possibile" & vbCrLf & _
" *** Avvisare CED *** ", vbCritical, NomeApplicazione
Exit Function
End If
' parte di codice per aggornare le celle
' funziona correttamente
Cells.EntireRow.AutoFit ' per adattare le celle alla dimensione
xlsWS1.Visible = False 'True
' xlsWS1.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
rs1.Close
Set rs1 = Nothing
' chiudo applicazione excel
xlsWB1.Close False
xlsApp.Quit
' anniento gli oggetti creati
Set xlsWS1 = Nothing
Set xlsWB1 = Nothing
Set xlsApp = Nothing
StampaApplicazioniUtente = True
End Function
Segnalibri