Solved when i exported to pdf it adds additional blank pages (1 Viewer)

Hi arnelgp
is it possible if you could help me add a msgbox when there is only pdfs in the subform list and no jpgs.
the message will tell the user that he can't convert to pdf cause there is no jpgs(images)
i tried the InStrRev(![Path] & "", ".jpg") <> 0 Then that you give me but it didn't seem to work with me.
 
here is the modified Click event:
Code:
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
 
arnelgp i can't thank you enough brother
god bless you.
 
Hi @arnelgp if you have time can you answer this problem please
using this application the conversion to pdf works great but after converting six or seven times it converts to empty pdfs (totaly blank) then i have to restart access app in order for it to convert normaly again
i wonder if this is a problem in the code or ram because my pc is relativly slow
what do you think is the problem.
 

Users who are viewing this thread

Back
Top Bottom