Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
ciao Nicola,
boh...! avrei ipotizzato prima del tuo ultimo post il problema potesse essere legato a qualche impostazione/restrizioni in termine di sicurezza della cartella...ma se di fatto il file da access viene esportato da test che hai esdeguito non è così...
prova il workAround che segue....cancello il file prima dell'esportazione se esiste ed in seguito lo ri-creo.
Ho aggiunto una minima gestione errori....e qualche altra modifica qua e la...
ciao, Sandro.
option explicit
on error resume next
dim fso
const strPathName="tuoFullPathDatabase.accdb.accdb" '<<<<<<<< da personalizzare
const strReportFullPath="tuoFullPathReportpdf.pdf" '<<<<<<<< da personalizzare
Set fso = CreateObject("Scripting.FileSystemObject")
call openDB
set fso=nothing
With Err
if .number<>0 then
MsgBox "ERR#" & .Number _
& vbNewLine & .Description _
, vbOKOnly Or vbCritical
end if
End With
sub openDB()
if not fso.fileexists(strPathName) then
msgbox "database inesistente",vbcritical, "Attenzione"
exit sub
end if
dim cnn, strConn, rst, lngRecNumber
Set cnn= CreateObject("ADODB.Connection")
Set rst= CreateObject("ADODB.Recordset")
strConn="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strPathName & ";Mode=Read;"
cnn.open strconn
rst.open "tuaQuery",cnn '<<<<<<<< da personalizzare
lngRecNumber=0
if not rst.eof then
lngRecNumber=rst.fields(0).value
end if
msgbox "individuati: " & lngRecNumber & " contratti in prossima scadenza", vbinformation, "Informazione"
if lngRecNumber>0 then
call printReport
call sendEmail
end if
rst.close
cnn.close
set cnn=nothing
set rst=nothing
end sub
sub printReport()
Dim MyAccess
dim scadenze
Set MyAccess = CreateObject("Access.Application")
If Not MyAccess Is Nothing Then
With MyAccess
.OpenCurrentDatabase strPathName, false
if fso.fileexists(strReportFullPath) then
fso.deletefile strReportFullPath
end if
.docmd.OutputTo 3,"tuoReport","PDF Format (*.pdf)",strReportFullPath '<<<<<<<< da personalizzare
.quit
End With
End If
set MyAccess=nothing
end sub
Sub sendEmail()
Dim outobj, mailobj
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
With mailobj
.To = "tuaemai@dominioit;******@dominio.it"
.Subject = "invio report"
.Body = "ciao, ti invio il report che trovi in allegato"
.Attachments.add strReportFullPath
.Display
End With
Set outobj = Nothing
Set mailobj = Nothing
End sub