473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to make a dynamic datareport?

i need to develop a dynamic datareport .
here by the word dynamic i mean that the contents of the report will vary according to the users input.

for eg : i am doing a search operation.and the result of the search will vary according to the input.

so i need to know how to map that varying result with the datareport.

and one more thing that i need to do all these thing with programming, i am not using the Dataenvironment and all those things.

help needed !!!!

thanks in advance
regards
vishwas
Sep 26 '07 #1
18 17751
creative1
274 100+
hi
It's little tricky. here some tips
1..... you need to create a connection string.
suppose RS in you r connection string.
RS.Open "your query ", Conn, adOpenKeyset, adLockOptimistic

2... Set data source and data members properties of your report
suppose RptInvoice is your report
With RptInvoice
Set .DataSource = Nothing
.DataMember = ""
Set .DataSource = RS.DataSource

3... set controls.
suppose you have lblName, lblAddress as your controls

.Sections("header").Controls("lblName").Caption = RS.Fields("company_name")
.Sections("header").Controls("lblAddress").Caption = RS.Fields("address")
.Sections("header").Controls("lblCity").Caption = RS.Fields("city")
.Sections("header").Controls("lblPostalCode").Capt ion = RS.Fields("postal_code")
.Sections("header").Controls("lblPhoneNo").Caption = RS.Fields("phone_number")
Sep 26 '07 #2
hi
It's little tricky. here some tips
1..... you need to create a connection string.
suppose RS in you r connection string.
RS.Open "your query ", Conn, adOpenKeyset, adLockOptimistic

2... Set data source and data members properties of your report
suppose RptInvoice is your report
With RptInvoice
Set .DataSource = Nothing
.DataMember = ""
Set .DataSource = RS.DataSource

3... set controls.
suppose you have lblName, lblAddress as your controls

.Sections("header").Controls("lblName").Caption = RS.Fields("company_name")
.Sections("header").Controls("lblAddress").Caption = RS.Fields("address")
.Sections("header").Controls("lblCity").Caption = RS.Fields("city")
.Sections("header").Controls("lblPostalCode").Capt ion = RS.Fields("postal_code")
.Sections("header").Controls("lblPhoneNo").Caption = RS.Fields("phone_number")

thanks a lot
but it is displaying the first record again and again for rs.recordcount times.

wat can be the probable sol for it?

thanks in advance
regards
vishwas
Sep 26 '07 #3
thanks a lot
but it is displaying the first record again and again for rs.recordcount times.

wat can be the probable sol for it?

thanks in advance
regards
vishwas

help needed!!!

regards
vishwas
Sep 27 '07 #4
creative1
274 100+
Sorry for a late reply. But I hope it will help you a little bit. I usually create dynamic reports using cobination of dataenviornemnt and queries at runtime. Data enviornemnt helps to design layout of report.
Anyways try this to loop displaying records
again suppose Rs is your recordset...Try this to display multiple records.

With RptInvoice
Set .DataSource = Nothing
.DataMember = ""
Set .DataSource = RS.DataSource

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''
This section to display information in the header section of the report
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''
.Sections("header").Controls("lblName").Caption = RS.Fields("company_name")
.Sections("header").Controls("lblAddress").Caption = RS.Fields("address")
.Sections("header").Controls("lblCity").Caption = RS.Fields("city")
.Sections("header").Controls("lblPostalCode").Capt ion = RS.Fields("postal_code")
.Sections("header").Controls("lblPhoneNo").Caption = RS.Fields("phone_number")

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''
This section to display information in the section1 of the report. A loop is ised to display multiple records.
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''


With .Sections("Section1").Controls
For i = 1 To .Count

If TypeOf .Item(i) Is RptTextBox Then
.Item(i).DataMember = ""
.Item(i).DataField = RS.Fields(i + 4).Name
'i+4 means ... leave first 5 in the query and display rest for them

End If
Next i



End With




End With
Sep 27 '07 #5
jrtox
89
hi vishwaskothari , we do have same problem.
but thanks creative1 for giving those idea.

ill try that when i got home.

but i still have a problem if its still working if theres a Parent and child commands
Sep 27 '07 #6
hi vishwaskothari , we do have same problem.
but thanks creative1 for giving those idea.

ill try that when i got home.

but i still have a problem if its still working if theres a Parent and child commands
thanks a lot Creative1
but how can we know how many controls should be added to control????
is there any sol for it?

well can u plz tell me the exact procedure of using dataenvironment.

thanks in advance
regards
vishwas
Sep 27 '07 #7
creative1
274 100+
hi guys
I will write an article on how we can create dynamic reports using DataEnviornment and Runtime queries. For your knowledge and help I'll work with parent-child commands. It will make the report useful for many other people. I'll try to create a simple example as well.
I hope to post is today.
regards
farhana
Sep 27 '07 #8
creative1
274 100+
Hi
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries, however working with complex reports is tricky
here are my suggestions and sequence of steps to create complex dynamic reports

Create a Parent-Child Command and create a DataReport
Suppose we have a database called company with two tables

Customers (customerID, company, contacttitle, address, city)
Orders (ordered, custoemerID, orderdate)

Create a report using Parent / Child relationship between queries.

Step 1:
Add Data Environment in the project. In the project Explorer windows
Right click on Project name -> Add -> DataEnvironment

You will see DataEnviornemnt1 under folder Designer in Project Explorer Windows. Double click DataEnviornment1 to get it displayed in the screen

Step 2:
Set connection to the database
Right Click on connection1-> select Provider tab-> select your provider name ( for Access select Microsoft Jet OLE DB Provider) -> select Next-> Select your database name(suppose your database name is company)-> Username and password -> Test connection
Once connection is successful go to step 3

Step 3:
Add a command (Parent Command)
Suppose we have table names customer
Right click connection1 -> select Add Command -> Right click on command1 -> select properties -> select radio button SQL statement -> type in your query(select * from customer) -> click Ok
You will see your fields under you command name (command1 in this case)

Step 4:
Add a command (Child Command)
Right click on command1-> add child command-> It will add a new command under command1-> right click on Command2 -> Click on SQL statement radio button -> type in your query (suppose you have a table orders to select record from: select * from orders)

Step-5 Relate Command2 with command1
Right click command2 -> select tab Relation-> select parent command (in this case Command1). Set relation definition by relating fields from both tables’ parent table (customer) and child table (customer).
Suppose customerID is relating both tables.

Step-6 View hierarchy information of your command
Right click on Command1 -> select Hierarchy info -> It will display relation of both commands(parent and child command) -> copy this all we are going to use this command in future to change it at runtime.
Step-7 Create a data report
Right click on Project1->select data report ->this will add DataReport1 under designer folder.

Step-8 Set Datareport1’s properties
Click on report scale under report tile to display report properties -> Right click on report -> select Add group header and footer -> It will add two more partitions in report group header (Section4) and group footer (Section5)

Step-9 Set Data source and Data members
Select you report then in the properties windows set following properties of data report
Datasource  set to DataEnviornment1
Datamember  Set to Command1

Step-10 Design Report Layout
Open you datareport1 and drag contents from command1 into Group Header (Section4)) and fields of Command2 into section1. To design a better interface you can drag fields of command2 in Section4. You can organize your report here. Set Report titles etc in report Header Section (Section2). Set page number and date in the footer section (Section3)
Tip: Group Footer section is used to display aggregates of the Section4 of you have any set in the hierarchy.

Step-11
Design a form to access data report
Add a form and add some commands buttons etc.
Connect a button (CommandButton1) to display/Print your report. If you execute you project now you will get a report that displays record from a database with parent chaild commands queries.

Now we proceed to make the report Dynamic

Make the Report Dynamic

Use your previous knowledge to do this. Create a report then following steps

Step-1 Set DataReport properties
Remove DataSource and DataMember for report that you previously used to design report.

Step-2 Reset Properties for Header Section
For group header section (Section4) delete DataMember property. Make sure that this property is empty for all fields in this section. Simply let it empty but do not remove DataFieds.

Step-3 Keep properties for child command fields in Sections1
Do not change properties for command2

Step-4 This is final and most important step in creating dynamic reports.

Here is a sample code to display an order details for all customers for a date range specified on form in datefrom.text and dateto.text

Code this for initialize event of dataeport.


Private Sub DataReport_Initialize()
Dim query As String ‘ this will hold our runtime query
Dim ToDate As String ‘ This will hold first date
Dim FromDate As String ‘ this will hold second date
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset

Conn.CursorLocation = adUseClient
Conn.ConnectionString = DataEnvironment1.Connection1
‘ Although connection is already set . But this can be used to set reset connection at runtime and connect to your database.
Conn.Open
‘get date values form form and store in string variables.
With form1
FromDate = .DateFrom.Value
ToDate = .DateTo.Value
End With

‘ As you copied text from hierarchy of command1, paste it here and do necessary changes in it. Such as in my example I am trying to specify my date requirements at runtime.



query = "SHAPE { "
query = query & "SELECT DISTINCT C.* "
query = query & "FROM Customers C INNER JOIN Orders O ON C.CustomerID = O.CustomerID "
query = query & "WHERE O.Orderdate "
query = query & "BETWEEN #" & strFrom & "# "
query = query & "AND #" & strTo & "# "
query = query & "ORDER BY C.CompanyName "
query = query & "} AS Command1 "
query = query & "APPEND ({ "
query = query & "SELECT Orders.* "
query = query & "FROM Orders "
query = query & "WHERE Orderdate "
query = query & "BETWEEN #" & FromDate & "# "
query = query & "AND #" & ToDate & "# "
query = query & "} AS Command2 "
query = query & "RELATE 'CustomerID' TO 'CustomerID') "
query = query & "AS Command2 "
RS.Open query, Conn, adOpenForwardOnly
Set DataReport1.DataSource = RS
End Sub


This will generate a complex and dynamic report in VB

I hope it will help you learn something
Farhana
Sep 28 '07 #9
Hi
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries, however working with complex reports is tricky
here are my suggestions and sequence of steps to create complex dynamic reports

Create a Parent-Child Command and create a DataReport
Suppose we have a database called company with two tables

Customers (customerID, company, contacttitle, address, city)
Orders (ordered, custoemerID, orderdate)

Create a report using Parent / Child relationship between queries.

Step 1:
Add Data Environment in the project. In the project Explorer windows
Right click on Project name -> Add -> DataEnvironment

You will see DataEnviornemnt1 under folder Designer in Project Explorer Windows. Double click DataEnviornment1 to get it displayed in the screen

Step 2:
Set connection to the database
Right Click on connection1-> select Provider tab-> select your provider name ( for Access select Microsoft Jet OLE DB Provider) -> select Next-> Select your database name(suppose your database name is company)-> Username and password -> Test connection
Once connection is successful go to step 3

Step 3:
Add a command (Parent Command)
Suppose we have table names customer
Right click connection1 -> select Add Command -> Right click on command1 -> select properties -> select radio button SQL statement -> type in your query(select * from customer) -> click Ok
You will see your fields under you command name (command1 in this case)

Step 4:
Add a command (Child Command)
Right click on command1-> add child command-> It will add a new command under command1-> right click on Command2 -> Click on SQL statement radio button -> type in your query (suppose you have a table orders to select record from: select * from orders)

Step-5 Relate Command2 with command1
Right click command2 -> select tab Relation-> select parent command (in this case Command1). Set relation definition by relating fields from both tables’ parent table (customer) and child table (customer).
Suppose customerID is relating both tables.

Step-6 View hierarchy information of your command
Right click on Command1 -> select Hierarchy info -> It will display relation of both commands(parent and child command) -> copy this all we are going to use this command in future to change it at runtime.
Step-7 Create a data report
Right click on Project1->select data report ->this will add DataReport1 under designer folder.

Step-8 Set Datareport1’s properties
Click on report scale under report tile to display report properties -> Right click on report -> select Add group header and footer -> It will add two more partitions in report group header (Section4) and group footer (Section5)

Step-9 Set Data source and Data members
Select you report then in the properties windows set following properties of data report
Datasource  set to DataEnviornment1
Datamember  Set to Command1

Step-10 Design Report Layout
Open you datareport1 and drag contents from command1 into Group Header (Section4)) and fields of Command2 into section1. To design a better interface you can drag fields of command2 in Section4. You can organize your report here. Set Report titles etc in report Header Section (Section2). Set page number and date in the footer section (Section3)
Tip: Group Footer section is used to display aggregates of the Section4 of you have any set in the hierarchy.

Step-11
Design a form to access data report
Add a form and add some commands buttons etc.
Connect a button (CommandButton1) to display/Print your report. If you execute you project now you will get a report that displays record from a database with parent chaild commands queries.

Now we proceed to make the report Dynamic

Make the Report Dynamic

Use your previous knowledge to do this. Create a report then following steps

Step-1 Set DataReport properties
Remove DataSource and DataMember for report that you previously used to design report.

Step-2 Reset Properties for Header Section
For group header section (Section4) delete DataMember property. Make sure that this property is empty for all fields in this section. Simply let it empty but do not remove DataFieds.

Step-3 Keep properties for child command fields in Sections1
Do not change properties for command2

Step-4 This is final and most important step in creating dynamic reports.

Here is a sample code to display an order details for all customers for a date range specified on form in datefrom.text and dateto.text

Code this for initialize event of dataeport.


Private Sub DataReport_Initialize()
Dim query As String ‘ this will hold our runtime query
Dim ToDate As String ‘ This will hold first date
Dim FromDate As String ‘ this will hold second date
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset

Conn.CursorLocation = adUseClient
Conn.ConnectionString = DataEnvironment1.Connection1
‘ Although connection is already set . But this can be used to set reset connection at runtime and connect to your database.
Conn.Open
‘get date values form form and store in string variables.
With form1
FromDate = .DateFrom.Value
ToDate = .DateTo.Value
End With

‘ As you copied text from hierarchy of command1, paste it here and do necessary changes in it. Such as in my example I am trying to specify my date requirements at runtime.



query = "SHAPE { "
query = query & "SELECT DISTINCT C.* "
query = query & "FROM Customers C INNER JOIN Orders O ON C.CustomerID = O.CustomerID "
query = query & "WHERE O.Orderdate "
query = query & "BETWEEN #" & strFrom & "# "
query = query & "AND #" & strTo & "# "
query = query & "ORDER BY C.CompanyName "
query = query & "} AS Command1 "
query = query & "APPEND ({ "
query = query & "SELECT Orders.* "
query = query & "FROM Orders "
query = query & "WHERE Orderdate "
query = query & "BETWEEN #" & FromDate & "# "
query = query & "AND #" & ToDate & "# "
query = query & "} AS Command2 "
query = query & "RELATE 'CustomerID' TO 'CustomerID') "
query = query & "AS Command2 "
RS.Open query, Conn, adOpenForwardOnly
Set DataReport1.DataSource = RS
End Sub


This will generate a complex and dynamic report in VB

I hope it will help you learn something
Farhana
first of all very very thanks to u for such a nice article.

will u plz elobrate the steps 1,2,3 of generating the dynamic datareport(Bold Part of this reply)
regards
vishwas
Sep 29 '07 #10
creative1
274 100+
Hi
Here is little explanation of the highlighted parts . I hope you will be able to understand it

Step-1 Set DataReport properties
Remove DataSource and DataMember for report that you previously used to design report.


Explanation: when we design our report structure by dragging command1 and command2 fields in out report. We set two properties of out report
1... Data member 2.. DataSource:
we don't need to reset these properties if we are working on static reports. If we are using parent-child command queries, it is very important to remove these properties in the property window. Otherwise report won't work. This is because when we use runtime queries, we set RS as datasource.

Step-2 Reset Properties for Header Section
For group header section (Section4) delete DataMember property. Make sure that this property is empty for all fields in this section. Simply let it empty but do not remove DataFieds.

Explanation: Generally speaking, group header section contains the parent part of query. for every fields in this section, remove value of DataMemeber property. However, it important to keep dataFields property so query can identify which fields goes where.

Step-3 Keep properties for child command fields in Sections1
Do not change properties for command2


For Section1, where we keep fields of out child query. Do not remove properties of this section let them same as you were using while designing layout.

regards
Farhana
Sep 30 '07 #11
GROG
34
Farhana..! u Make my day.. the lengthy write up really works.. thanx a lot..god bless u.. wish could treat u a lunch/ dinner.. he.. hmm .. still need ur help.. how to insert page number in a report..? i.e page # and page # of ##
Oct 1 '07 #12
GROG
34
And also todays date.. as in Date printed < dd/mm/yyyy>
Oct 1 '07 #13
GROG
34
Sorry all.. found it.. the date and the page num.. Thanks
Oct 1 '07 #14
creative1
274 100+
My pleasure ! to help you ... I posted this message in article as well so it may be helpful for others.
regards
farhana
Oct 1 '07 #15
srbh
1
that article helped me a lot....... thanks to farhana....!!
Oct 9 '12 #16
Thanks creative1-farhana for your great work. Your post will help the developers a lot. keep it up. May God bless you.
If I have any query I will surely approach you. You are a good teacher.
regards,
Anjali
Jul 25 '13 #17
Chege
4
Creative1,

Thanks so much for this informative and educative material. I have followed your Dynamic report creation. But I am getting an error.
First i have a form with two TextBoxes that hold From Date(DateFrom) and To Date (DateTo)values.

I have copied the code and pasted on DataReport_Initialize(). When I run the program it says:

Run-time error '-2147217913(80040e07)':

Syntax error in date in query expression 'O.Orderdate BETWEEN ## AND ##'.


It then takes me to
RS.Open query, Conn, adOpenForwardOnly
after clicking debug.

I have noticed that my strFromand strTo are both empty but my FromDate and ToDate have values.

While getting dates from Form i am using:
With frmDataEnv
FromDate = .DateFrom.Text
ToDate = .DateTo.Text
End With

NB: it tells me method not supported when i use .DateFrom.Value or .DateTo.Value

Kindly let me know where i am going wrong.

Thanks

Chege
Sep 17 '13 #18
Chege
4
Phew!!!

Creative1, I have nailed it!!! Great....

Thanks a million.

Simon
Sep 17 '13 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: berthelot samuel | last post by:
Hi everyone, I am currently trying to write a report based on a View of SQL Server. Basically, I have 3 tables : Hardware, SoftwareInstalled and Software with SoftwareInstalled that keeps track of...
1
by: Speed | last post by:
How to write informations from database in Page Header section like in Detal section of DataReport?
1
by: Gary | last post by:
Dear Is it possible using ASP to call VB6 DataReport? if yes any reference of creating those com+ of DataReport and Call method? Gary
0
by: David | last post by:
I have tried unsccessfully, to pass parameter values to a stored procedure that I'm using for a datareport. The stored procedure requires the input of an start date and end date for a search...
5
by: anoopgopal007 | last post by:
Hi, I am using vb6 and datareport. I am updating the tables whle the program running. But the datareport doesnot show the updated information. Its always shows the previous value. But...
6
by: pramodrepaka | last post by:
hi this is pramod i am facing a small problem Private Sub Command_Click() Dim a As String a = InputBox("enter empno") If rs.State = 1 Then rs.Close rs.Open "select * from microbiology...
0
by: nishjee | last post by:
Hello friends, i need visual basic 6.0 code to export a datareport to html other than the defult option coming with datareport. I need this very urgently because when i am exporting the datareport...
9
smartchap
by: smartchap | last post by:
I have a table having 3 fields viz. SNo, FName and LName. The table has 10 records having SNo from 1 to 10. In DataReport I have 3 labels and 3 textboxes. I want to display all records from 1 to 10...
1
by: MaryKJolly | last post by:
I got this sample project from a website. But there is some syntax error in the statement which contains the CDate function. I can't detect the error? Can enybody help me? SUMMARY This article...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.