الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

رجاءا هل من شرح لهذه الدالة الخاصة بالطباعة

مغلق
بدأه biskra في 10 مايو 2004 · 4 رد · 917 مشاهدة · في قواعد بيانات Microsoft Access
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذه الدالة تتعلق بطباعة التقارير أريد من من له معرفة أن يشرحها لنا و يدلنا على كيفية اٍستعمالها.

Public Function PrintOrPreview(ReportName As String, Optional strFilter As String, _
    Optional strFile As String, Optional AlternateReportName As String, Optional Warning As String) As Boolean
' returns 1 when completed     ReportName is name of report to print, strFilter is filter to use to print report
' give user option of canceling [2], printing immediately [7] or previewing on screen first [1]
' if the value DoNotAsk is passed to strFile, then user will NOT be asked if report should be sent to file
' if user selects file option, a file location dialog box automatically comes up as part of the output statement _
and strFile is shown as the default file name
' AlternateFileName is the report to use when sending to a file, since filtering is not available
' Warning is the message to show to the user when sending to a file (example: All data will be reported)
On Error GoTo Err_PrintOrPreview
    Dim intPrintHow As Integer
    Dim Response As Integer
    Dim strPath As String
    Dim strFileName As String
    intPrintHow = MsgBox("Preview report on screen?", vbYesNoCancel, "Print or Preview Report")
    If intPrintHow = 2 Then
        Exit Function
    End If
    If intPrintHow = 7 Then
        ' allow sending report to a file only when the value "DoNotAsk" has NOT has been passed to this function
        If strFile <> "DoNotAsk" Then
            intPrintHow = MsgBox("Send to file?", 259, "Send to file or print") ' Yes/No/Cancel with No as default
            If intPrintHow = 2 Then
                Exit Function
            End If
            If intPrintHow = 7 Then
                DoCmd.OpenReport ReportName, acViewNormal, , strFilter
            Else
                If intPrintHow <> 6 Then
                    Exit Function
                Else
                    If intPrintHow = 6 Then
                    ' note report is NOT filtered when sent to file
                        If Not IsNull(Warning) Then
                            Response = MsgBox(Warning, vbOKCancel, "Warning when sending report to a file")
                            If Response <> 1 Then ' 1 returned when user clicks OK
                                MsgBox "Report cancelled!", vbExclamation
                                Exit Function
                            End If
                        End If
                    ' ask user for path to save file and then ask for file name (showing default name)
                        strFileName = InputBox("Enter name of file (must end in .RTF)", "Name of file", strFile)
                        If IsNull(strFileName) Then
                            MsgBox "Report cancelled -- no file name specified!", vbExclamation
                            Exit Function
                        End If
                        If Len(strFileName) < 4 Or MID$(strFileName, Len(strFileName) - 3, 4) <> ".RTF" Then
                            strFileName = strFileName & ".RTF"
                        End If
                        strPath = InputBox("Where should the file be saved (enter the path)?", "Location to save file")
                        If IsNull(strPath) Or strPath < " 0" Then
                            MsgBox "Report cancelled -- no path specified!", vbExclamation
                            Exit Function
                        End If
                        If MID$(strPath, Len(strPath), 1) <> "\" Then
                            strPath = strPath & "\"
                        End If
                        strFile = strPath & strFileName
                        If IsNull(AlternateReportName) Then
                            DoCmd.OutputTo acOutputReport, ReportName, acFormatRTF, strFile
                        Else
                            DoCmd.OutputTo acOutputReport, AlternateReportName, acFormatRTF, strFile
                        End If
                    Else
                        MsgBox "Report cancelled!", vbExclamation
                    End If
                End If
            End If
        Else
            DoCmd.OpenReport ReportName, acViewNormal, , strFilter
        End If
    Else
        DoCmd.OpenReport ReportName, acViewPreview, , strFilter
    End If
Exit_PrintOrPreview:
    Exit Function
Err_PrintOrPreview:
    Select Case Err
        Case 2501       ' message about invoking Cancel action (to be ignored)
        Resume Exit_PrintOrPreview
    End Select
    MsgBox Err.Description
    Resume Exit_PrintOrPreview
End Function
#2

أخي biskra

هي مشروحة في هذه الأسطر :

 returns 1 when completed     ReportName is name of report to print, strFilter is filter to use to print report
' give user option of canceling [2], printing immediately [7] or previewing on screen first [1]
' if the value DoNotAsk is passed to strFile, then user will NOT be asked if report should be sent to file
' if user selects file option, a file location dialog box automatically comes up as part of the output statement _
and strFile is shown as the default file name
' AlternateFileName is the report to use when sending to a file, since filtering is not available
' Warning is the message to show to the user when sending to a file (example: All data will be reported)
#3

لنفترض أنني صممت زر للطباعة كيف أستدعيها, و كيف أختار واحد من الخيارات, معذرة أخي مهند معرفتي للغة الأنجليزية محدودة جدا.

#4

أخي الكريم هذه الدالة لا يوجد بها شيء جديد سوى أنها دمجت أمر الطباعة والمعاينة والإرسال إلى ملف RTF في تعليمة واحدة وهذا شرح لها

PrintOrPreview(ReportName As String, Optional strFilter As String,   Optional strFile As String, Optional AlternateReportName As String, Optional Warning As String

شرح الممرات :

ReportName : اسم التقرير المطلوب

strFilter : -اختياري- عبارة sql من أجل استخدامها كفلتر لبيانات التقرير

strFile : -اختياري- اسم ملف افتراضي في حال الرغبة بطباعة التقرير إلى ملف .

AlternateReportName : -اختياري- اسم تقرير بديل في حال طباعة إلى ملف

Warning : -اختياري- نص رسالة التأكد من طباعة التقرير إلى ملف

يقوم هذا التابع بالسؤال أولاً عن الرغبة في معاينة التقرير على الشاشة (نعم/لا/إلغاء الأمر)

إذا اخترنا لا يقوم التابع بفحص قيمة strFile إذا كانت تساوي "DontAsk" يقوم بطباعة التقرير على الطابعة

وإلا فإنه يسأل : إرسال التقرير إلى ملف (نعم/لا/إلغاء الأمر)

إذا اخترنا لا يقوم بطباعة التقرير بشكل عادي

إذا اخترنا نعم فإنه يعرض رسالة تأكد من الرغبة في الطباعة إلى ملف

إذا اخترنا Ok يسأل عن اسم ملف التقرير والقيمة الافتراضية في مربع إدخال الاسم تكون هي قيمة strFile ثم يسأل عن مسار الملف

وبعد التأكد من صلاحية الاسم والمسار يقوم بفحص قيمة AlternateReportName إذا كان موجوداً يستخدمه وإلا فإنه يستخدم التقرير الأساسي ويرسله إلى الملف

#5

مشكور أخي مهند, هذا الشرح يساعد على تعلم التعامل مع الأكواد و فهم أوامرها.

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…