Private Sub CommandConvertToPdf_Click()
Dim Numberofdocuments As Integer, NumDoc As Long
NumDoc = Me.IDD
'Numberofdocuments = DCount("IDD", "QPicOfConseller01")
Numberofdocuments = DCount("IDD", "Images", "IDD =" & NumDoc & " And [Path] Like '*.jpg'")
If Numberofdocuments = 0 Then
'MsgBox "áÇÊæÌÏ ÕæÑÉ áÊÍæíáåÇ", , "ÕÝÍÉ ãÍãæÏ ÚÈÏ ÇáÛÝÇÑ"
MsgBox "No image to convert!"
Exit Sub
Else
SetPathOfFiles
'NumDoc = Me.IDD
If Len(Dir(PathOfFile & Forms![Form1]![IDD], vbDirectory)) = 0 Then
MkDir PathOfFile & Forms![Form1]![IDD]
End If
DoCmd.OpenReport "ReportToPdf", acViewPreview, , , acHidden
DoCmd.OutputTo acReport, "ReportToPdf", "PDFFormat(*.pdf)", PathOfFile & NumDoc & "\" & NumDoc & "-" & Format(Now, "d-m-yy_h-n-s") & ".pdf"
DoCmd.Close acReport, "ReportToPdf", acSaveNo
End If
'Deletes jpgs after convert
Dim sFile As String
If Me!OptionDeletePicAfterConvertPDF = -1 Then
With Me!ImagesSubform.Form.RecordsetClone
If Not (.BOF And .EOF) Then
.MoveFirst
End If
Do Until .EOF
If InStrRev(![Path] & "", ".jpg") <> 0 Then
sFile = ![Path]
.Delete
On Error Resume Next
If Len(Dir$(sFile)) <> 0 Then
Kill sFile
End If
On Error GoTo 0
End If
.MoveNext
Loop
End With
Me.PicView.Requery
End If
Dim Ttb2 As Recordset
Set Ttb2 = Me!ImagesSubform.Form.RecordsetClone 'CurrentDb.OpenRecordset("Image")
Ttb2.AddNew
Ttb2![IDD] = NumDoc
Ttb2![Path] = PathOfFile & NumDoc & "\" & NumDoc & "-" & Format(Now, "d-m-yy_h-n-s") & ".pdf"
Ttb2.Update
Me.ImagesSubform.Requery
End Sub