تفضل استاذ @jo_2010 كود الزر بعد التعديل بطلبك .ووافني بالرد .
Private Sub أمر1595_Click()
Dim TaskDialog As Y_CTaskDialog
Set TaskDialog = New Y_CTaskDialog
Dim sSubReport As String
sSubReport = Screen.ActiveControl.Caption
' مسار التصدير
Dim sBasePath As String
Dim sFolder As String
Dim sPDF As String
sBasePath = CurrentProject.Path
sFolder = sBasePath & "\MyReports"
' إنشاء المجلد إن لم يكن موجودًا
If Dir(sFolder, vbDirectory) = "" Then
MkDir sFolder
End If
With TaskDialog
.Init
.ParenthWnd = Me.hwnd
.Flags = TDF_RTL_LAYOUT Or TDF_USE_COMMAND_LINKS _
Or TDF_USE_IMAGERES_ICONID_BUTTON
.AddCustomButton 101, _
" طبـاعـة كـل التقـارير بتاريخ " & " / " & DDate & vbLf & _
" عدد التقارير " & URn & " تقرير ", 5380
.AddCustomButton 102, _
" طبـاعـة تقــريــــر واحــــد " & vbLf & _
" باســــم / " & PNAME & " ", 5351
.AddCustomButton 103, _
" تــراجــــــع عـن الطبــاعـة ", 5315
.SetWindowsButtonIconSize 32
.MainInstruction = "جمعية حماية البيئة من التلوث"
.Content = "معمـل الام والطفــل"
.IconMain = 76
.Title = "طباعـــة"
.Width = 250
.ShowDialog
Select Case .ResultMain
' ===== الحالة 101 =====
Case 101
Me.Refresh
' مسار واسم ملف PDF
sPDF = sFolder & "\AllReports_" & _
Format(Me.DDate, "yyyy-mm-dd") & ".pdf"
' فتح التقرير في وضع مخفي
DoCmd.OpenReport "Y_N_Report", acViewPreview, , _
"ddate = #" & Format(Me.DDate, "yyyy-mm-dd") & "# AND NOT IsNull(colour)", _
acHidden, sSubReport
' تصدير التقرير إلى PDF
DoCmd.OutputTo acOutputReport, "Y_N_Report", acFormatPDF, sPDF, False
' إغلاق التقرير
DoCmd.Close acReport, "Y_N_Report"
' فتح ملف الـ PDF بعد التصدير
Application.FollowHyperlink sPDF
' ===== الحالة 102 =====
Case 102
Me.Refresh
Dim PatientName As String
Dim FileDate As String
Dim RLM As String
Dim LRM As String
RLM = ChrW(&H200F) ' Right-To-Left Mark
LRM = ChrW(&H200E) ' Left-To-Right Mark
' اسم المريض
PatientName = Me.PNAME
' تنظيف الرموز غير المسموحة
PatientName = Replace(PatientName, "/", "-")
PatientName = Replace(PatientName, "\", "-")
PatientName = Replace(PatientName, ":", "-")
' التاريخ
FileDate = Format(Date, "dd-MM-yyyy")
' اسم الملف (اتجاه مضبوط 100%)
sPDF = sFolder & "\" & _
RLM & PatientName & RLM & "_" & LRM & FileDate & ".pdf"
' فتح التقرير بشكل مخفي
DoCmd.OpenReport "Y_N_Report", acViewPreview, , _
"[PCode]=" & Me.PCode, acHidden, sSubReport
' تصدير PDF
DoCmd.OutputTo acOutputReport, "Y_N_Report", acFormatPDF, sPDF, False
' إغلاق التقرير
DoCmd.Close acReport, "Y_N_Report"
' فتح ملف الـ PDF
Application.FollowHyperlink sPDF
Case 103
Exit Sub
End Select
End With
Set TaskDialog = Nothing
End Sub