When I learned how to use the report in the data center charging system, the first question is what the report is? What is the role of a report?
Reports are the basic measures and methods for enterprise management and the basic business requirements of enterprises. Reports can help enterprises access and format data, the data is presented to users in a reliable and secure manner. In-depth insight into enterprise operation is a powerful driving force for enterprise development.
In the future, reports play an increasingly important role in companies. The first time the data center charging system was used to prepare reports, it included the basic principles and content of reports, download the report builder and try it first. Although it is easy to create, it is powerful and fun. Important knowledge points in connection with VB, reports, and databases are as follows:
Statement of the Report in VB
Declare the statement in VB (weekly statement as an example ):
Option explicitprivate withevents objweekliybill as grprolibctl. gridppreport 'declares the objweekliybill object
What does withevents mean? What statement?
Dim withevents object variable as Class Name
This method is used to load events of this class. After withevents, you can see the events of this class in the code editing window (if any ).
Unlike controls, double-click controls to edit events.
Note the following constraints when using the withevents variable:
1. withevents variables cannot be derived object variables. That is to say, it cannot be declared as an as object-the class name must be specified when the variable is declared.
2. The withevents variable cannot be declared as new. You must explicitly create an event source object and assign it to the withevents variable.
For example:
Private sub form_load () dtpbegindate. value = date dtpenddate. value = date set objweekliybill = new grprolibctl. gridppreport 'create an event source event
3. The withevents variable cannot be declared in the standard module. It can only be declared in the class module, form module, and other definition class modules.
You cannot create an array of withevents variables.
Show selected time
In the IDC charging system, there is a weekly bill to show the selected time. How can this problem be achieved?
Insert parameters in the report's main object, right-click-insert-parameters, as shown in the following figure:
,
Insert a text box into the Template
Programs to be written in VB:
Private sub form_load () dtpbegindate. value = date dtpenddate. value = date set objweekliybill = new grprolibctl. gridppreport 'create event source event objweekliybill. loadfromfile (App. path & "\ weekliybill. GRF ") objweekliybill. detailgrid. recordset. connectionstring = "filedsn = room_charge_new.dsn; uid = sa; Pwd = 123456" grdweekliybill. report = objweekliybill grdweekliybill. start objweekliybill. parameterbyname ("begindate "). value = format (dtpbegindate. value, "yyyy-mm-dd") 'displays the start time of objweekliybill. parameterbyname ("enddate "). value = format (dtpenddate. value, "yyyy-mm-dd") 'displays the end time of end sub.
Final Result
Report refresh
'Refresh the report private sub cmdrefresh_click () dim strsql as string dim strmsg as string dim objrsweekliybill as ADODB. recordset dim objrsdaliybill as ADODB. recordset if dtpbegindate. value> dtpenddate. value then' condition restriction msgbox "the end date cannot be earlier than the start date! ", Vbokonly + vbexclamation," warning "Exit sub end if 'selected strsql =" select * From checkday_info where checkdate> =' "& dtpbegindate. value & "'" & "and checkdate <='" & dtpenddate. value & "'" set objrsdaliybill = executesql (strsql, strmsg) strsql = "select * From checkweek_info" set objrsweekliybill = executesql (strsql, strmsg) do while objrsweekliybill. EOF = false objrsweekliybill. delete objrsweekliybill. movenext loop 'is updated to do while objrsdaliybill. EOF = false' checks whether data exists with objrsweekliybill. addnew. fields (0) = objrsdaliybill. fields (0 ). fields (1) = objrsdaliybill. fields (1 ). fields (2) = objrsdaliybill. fields (2 ). fields (3) = objrsdaliybill. fields (3 ). fields (4) = objrsdaliybill. fields (4 ). fields (5) = objrsdaliybill. fields (5 ). update objrsdaliybill. movenext end with loop grdweekliybill. refresh 'refresh objweekliybill. parameterbyname ("begindate "). value = dtpbegindate. value objweekliybill. parameterbyname ("enddate "). value = dtpenddate. value end sub
Print report
Private Sub cmdPrint_Click() objWeekliyBill.[Print] (True) End Sub
Print preview
Private Sub cmdPreView_Click() objWeekliyBill.PrintPreview (True) End Sub
Learning is a process of repetition, accumulation, and exploration. This process may not have obvious results in a short time. But when we look back, we will find ourselves growing a lot and gaining a lot. Come on!