I am trying to create PDF files (1 File per record). but i am stuck and it is not working below is my code.
if i select NO it create all the PDF files in one single file
but if i Choose No it give me Error :
Code:
Dim FileName As String
Dim FilePath As String
'FileName = Me.Hoten
'FilePath = "D:\" & FileName & ".pdf"
'DoCmd.OutputTo acOutputReport, "IIn", acFormatPDF, FilePath
Dim rs As Object
Dim iAns As Integer
Dim sFolder As String
iAns = MsgBox("Do you want to print ALL records?" & vbCrLf & vbCrLf & _
" Choose 'Yes' to print all records" & vbCrLf & _
" Chose 'No' to print the current record", vbQuestion + vbYesNoCancel)
If iAns = vbYes Or iAns = vbNo Then
sFolder = BrowseForFolder("Select a Folder to save the pdf")
If Len(Trim$(sFolder)) = 0 Then
sFolder = Environ("UserProfile") & "\Documents\"
MsgBox "You have not selected any folder. The pdf(s) will be saved to Documents folder.", vbInformation
End If
End If
If iAns = vbYes Then
Set rs = Me.Recordset
With rs
If .RecordCount < 1 Then
Exit Sub
End If
.MoveFirst
Do Until .EOF
FileName = UCase(Me.StudentFullName & "")
FilePath = sFolder & FileName
Call forceMKDir(FilePath)
FilePath = FilePath & "\" & FileName & ".pdf"
'FilePath = "D:\" & FileName & ".pdf"
'FilePath = "C:\ARNEL\" & FileName & ".pdf"
If Len(Dir$(FilePath)) <> 0 Then
Kill FilePath
End If
'DoCmd.SetParameter "p_HOTEN", FileName
TempVars("p_Hoten") = FileName
DoCmd.OutputTo acOutputReport, "IIn_all", acFormatPDF, FilePath
.MoveNext
Loop
End With
On Error Resume Next
TempVars.Remove "p_Hoten"
On Error GoTo 0
ElseIf iAns = vbNo Then
FileName = UCase(Me.StudentFullName & "")
FilePath = sFolder & FileName
Call forceMKDir(FilePath)
FilePath = FilePath & "\" & FileName & ".pdf"
'FilePath = "D:\" & FileName & ".pdf"
'FilePath = "C:\ARNEL\" & FileName & ".pdf"
If Len(Dir$(FilePath)) <> 0 Then
Kill FilePath
End If
DoCmd.OutputTo acOutputReport, "Nest-Term1-Bill", acFormatPDF, FilePath
End If
if i select NO it create all the PDF files in one single file
but if i Choose No it give me Error :