اذهب الي المحتوي
أوفيسنا

تصميم تقرير برمجيا


الردود الموصى بها


 

Sub CreateNewReport()
Dim rptCustomers As Access.Report
Dim strReportName As String
Dim aoAccessObj As AccessObject
Dim txtTextBox As Access.TextBox
Dim lblLabel As Access.Label
Dim strSQL As String
Dim intPosition As Integer
'set the name of the new report
strReportName = "Customers”"
strSQL = "SELECT * FROM Customers ORDER BY CompanyName”"
'delete any existing report with that name
For Each aoAccessObj In CurrentProject.AllReports
If aoAccessObj.name = strReportName Then
DoCmd.DeleteObject acReport, strReportName
End If
Next aoAccessObj
'create a new Customers Report
Set rptCustomers = CreateReport
With rptCustomers
'set the report record source to the SQL Statement
.RecordSource = strSQL
'set the height, caption, and other report options
.section("Detail").Height = 500
.Caption = "Client Contact List”"
End With
'add a Company Name label and text box to the report
intPosition = 0
Set txtTextBox = CreateReportControl(rptCustomers.name, acTextBox, -acDetail, , "CompanyName", intPosition)
txtTextBox.name = "txtCompanyName”"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.name, acLabel, -acPageHeader, , , intPosition)
lblLabel.name = "lblCompanyName”"
lblLabel.Caption = "Company Name”"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Name label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 350
Set txtTextBox = CreateReportControl(rptCustomers.name, acTextBox, -acDetail, , "ContactName", intPosition)
txtTextBox.name = "txtContactName”"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.name, acLabel, -acPageHeader, , , intPosition)
lblLabel.name = "lblContactName”"
lblLabel.Caption = "Contact Name”"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Title label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 500
Set txtTextBox = CreateReportControl(rptCustomers.name, acTextBox, -acDetail, , "ContactTitle", intPosition)
txtTextBox.name = "txtTitle”"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.name, acLabel, -acPageHeader, , , intPosition)
lblLabel.name = "lblTitle”"
lblLabel.Caption = "Title”"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Phone label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 1000
Set txtTextBox = CreateReportControl(rptCustomers.name, acTextBox, -acDetail, , "Phone", intPosition)
txtTextBox.name = "txtPhone”"
Set lblLabel = CreateReportControl(rptCustomers.name, acLabel, -acPageHeader, , , intPosition)
lblLabel.name = "lblPhone”"
lblLabel.Caption = "Phone”"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'save and close the new report
DoCmd.Save , strReportName
DoCmd.Close
End Sub

عند تنفيذ هذا الامر تظهر رسالة يجب ان تستخدم رقم مقطع وليس سلسلة احرف 

ارجو المساعدة في حل هذه المشكلة 

ومن عنده طريقة لتصميم التقرير برمجيا فجزاه الله عني خير الجزاء

رابط هذا التعليق
شارك

السلام عليكم

أخي الكريم هناك بعض الأخطاء في الكود الذي وضعته و سوف أشرحها لك بإذن الله:

أولا: أنت تستخدم أكسس عربي و لذلك يجب تغيير هذه الكلمة Detail في السطر الموالي بالكلمة تفصيل

.section("Detail").Height = 500

ثانيا: في السطر الموالي و الأسطر المشابهة له احذف علامة الناقص من الكلمة الملونة بالأحمر و اترك acPageHeader فقط

Set lblLabel = CreateReportControl(rptCustomers.name, acLabel, -acPageHeader, , , intPosition)

ثالثا:  في جميع الأسطر المشابهة لهذين السطرين 

lblLabel.name = "lblContactName”"
lblLabel.Caption = "Contact Name”"

احذف علامة الاقتباس من التسمية لأنها تعارض قواعد التسميات في الأكسس و أتركها كما يلي:

lblLabel.name = "lblContactName"
lblLabel.Caption = "Contact Name"

و في الأخير هذا هو كودك بعد التصحيح:

Sub CreateNewReport()
Dim rptCustomers As Access.Report
Dim strReportName As String
Dim aoAccessObj As AccessObject
Dim txtTextBox As Access.TextBox
Dim lblLabel As Access.Label
Dim strSQL As String
Dim intPosition As Integer
'set the name of the new report
strReportName = "Customers”"
strSQL = "SELECT * FROM Customers ORDER BY CompanyName”"
'delete any existing report with that name
For Each aoAccessObj In CurrentProject.AllReports
If aoAccessObj.Name = strReportName Then
DoCmd.DeleteObject acReport, strReportName
End If
Next aoAccessObj
'create a new Customers Report
Set rptCustomers = CreateReport
With rptCustomers
'set the report record source to the SQL Statement
.RecordSource = strSQL
'set the height, caption, and other report options
.Section("تفصيل").Height = 500
.Caption = "Client Contact List”"
End With
'add a Company Name label and text box to the report
intPosition = 0
Set txtTextBox = CreateReportControl(rptCustomers.Name, acTextBox, acDetail, , "CompanyName", intPosition)
 txtTextBox.Name = "txtCompanyName"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.Name, acLabel, acPageHeader, , , intPosition)
lblLabel.Name = "lblCompanyName"
lblLabel.Caption = "Company Name"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Name label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 350
Set txtTextBox = CreateReportControl(rptCustomers.Name, acTextBox, acDetail, , "ContactName", intPosition)
txtTextBox.Name = "txtContactName"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.Name, acLabel, acPageHeader, , , intPosition)
lblLabel.Name = "lblContactName"
lblLabel.Caption = "Contact Name"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Title label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 500
Set txtTextBox = CreateReportControl(rptCustomers.Name, acTextBox, acDetail, , "ContactTitle", intPosition)
txtTextBox.Name = "txtTitle"
txtTextBox.Width = 1800
Set lblLabel = CreateReportControl(rptCustomers.Name, acLabel, acPageHeader, , , intPosition)
lblLabel.Name = "lblTitle"
lblLabel.Caption = "Title"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'add a Contact Phone label and text box to the report
intPosition = txtTextBox.Width + txtTextBox.Left + 1000
Set txtTextBox = CreateReportControl(rptCustomers.Name, acTextBox, acDetail, , "Phone", intPosition)
txtTextBox.Name = "txtPhone"
Set lblLabel = CreateReportControl(rptCustomers.Name, acLabel, acPageHeader, , , intPosition)
lblLabel.Name = "lblPhone"
lblLabel.Caption = "Phone"
lblLabel.Height = txtTextBox.Height
lblLabel.Width = txtTextBox.Width
lblLabel.FontBold = True
'save and close the new report
DoCmd.Save , strReportName
DoCmd.Close
End Sub

 

رابط هذا التعليق
شارك

جزاك الله عني خير الجزاء متشكر جدا لاهتمامك 

سؤال آخر بهذه الطريقة يمكن تصميم تقرير من خلال الكود مع اضافة وحذف الحقول حسب الحاجة ارجو الافادة وهل يوجد طريقة اخري اسهل ام لا شكرا

رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information