Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Data Report Designer 4

Status
Not open for further replies.

Sam13

Technical User
May 31, 2001
5
US
Hi there, I'm relatively new to working with VB and databases. I'm working on a project that is using the Data Environment and the Data Report Designer to create reports. This is my first time using these aspects of VB. I've stumbled my way through setting up some reports but I'm having trouble with a few things.

First, How do you get the report to show in a landscape format rather than portrait? Is this option even available??

My second question Is a bit more involved. Basically when I create the reports, I'm using the data environment connection to create a query of my tables using parent/child commands and SQL statements. The issue is that When my parent item has no data in the child portion then the report still creates a line item for the parent. I want to eliminate this line item and only have the report show parent data that has child data. I hope I'm being clear. I'm a bit lost on how to do this.

My third question is can the Data Report Designer be used with an ADO control? Basically I want to be able to search the database on criteria the user enters and print a report using the recordset returned by the search. Any thoughts on the best way to print such a report would be great.

Thanks in advance for the help.

Sam
 

I would use a stored procedure to return only the records you want printed on the report. This will also allow you to create parameters to pass to the stored procedure to allow the user to enter criteria.

Let me know if you would like an example. Send me your email address and I will send you a sample vb project.

bbosley
bbosley@pisc.com
 
bbosley,
i was reading through this thread and it seem like i'm in the same boat as sam13. Do you mind posting a sample for both of us.

thanks,
 
Basically, here's what I ended up doing:

1. landscape - still can't figure out how to landscape the data report. I ended up adjusting the margins of the data report so that all my fields could be displayed. The reports now have a right and left margin of about 1cm instead of 1in. which will work for my purposes.
2. I stopped using parent/child relationships to define my report and used one command with a complex SQL statement and used the parameters and grouping sections of the command properties window. I used the SQL builder to help in creating my SQL statement. I learned more about what I can do with SQL this way. I'm still by no means an expert though. The SQL builder is a good tool for those of us who are just learning SQL. I still don't know how to create a stored procedure.
3. I'm no longer trying to use ADO controls with the data report object, for all my research it doesn't look like ado controls can be used with the data report object.
 
the landscape setting (and all other printer settings like paper type) can only be set at the settings of your printer, so before you preview the report, you have to change the settings of your printer.

if you want to use ado recordsets in your data report, all you have to do is set up the proper fields your report will be bound into (by setting the datafield property to then name of the field in the recordset) then code the datasource property through code by assing the value of the recordset to it

example

Set DataReport.DataSource = ADOControl.DataSource

or

Set DataReport.DataSource = ADODB.Recordset

both works OK

hope i could help
 
I have found altering printer settings in VB via the printer object frustrating, and usually ineffective. The reason seems to be that changes to the printer object only affect the main VB program, and not linked items like the Data Report designer! The only certain way to change printer settings in VB is to make changes to the system default printer via API calls - examples in MS Q198860 Q173981 Q190218.

To change the orientation of a Data Report in code, you can use:

datareport1.Orientation = rptOrientLandscape
 
Sending parameters to your report from user selected values from a combobox ( for that matter from any control):
Suppose your dataenvironment object name is 'deReports', your command name is 'country' (command name is where your sql is), your combobox name is 'cbosource', and 'dataReport1' is your report namethen do the following in your click event to generate the report:

deReports.country cboSource.List(cboSource.ListIndex)
DataReport1.Show

If you want grab the value selected by the user from the combo box into a variable (say 'vValue') and do the following:
deReports.country vValue
DataReport1.Show

You can send as many values depending on the number of parameters you are expecting in you sql separating them with a comma.
In the following example I am sending 3 parameters that I used for grouping in my sql

deReports.Command1_Grouping strRptCountry, strRptSource, strRptTopic

rptCountry.Show

You can actually achieve the same result with ADO and without dataenvironment object.
Of course, I am able to see the data in my report. I am working on grouping fields using ADOS without dataenvironment object.

I hope this would help you to solve your problem


 
Just before you call the datareport.show method, set up the properties, such as:


deReporting.comAuthors
With drAuthorsDetail
'height and width are for the reports container window, not the report
.Height = 13965
.Width = 16965
.Orientation = rptOrientLandscape
.TopMargin = 400
.BottomMargin = 400
.LeftMargin = 400
.RightMargin = 400
'the caption is for the reports container as well.
.caption = strTitle
.Show vbModal
End With

There is alot more you can do - just play around a little.
 
I am also trying to use the Data Report Designer to generate a report with parameters. My Data Environment name is simply 'DataEnvironment1', and my SQL statement is in a child command thats part of the details section of a grouping (I hope that makes sense ... there is only one grouping).

My Click Event has the following code:

DataEnvironment1.Codes_Grouping List1.ListIndex
DeptReport_Detailed.Show

where List1 is a simple listbox containing numbers 1-12.

The problem is that I recieve the following error.
Compile error: Wrong number of arguments or invalid property assignment.

My SQL statement is as follows:
SELECT * FROM tbl_FaxData WHERE DatePart("m",[AcknowledgedTime]) = k

I am using k as a variable name, because it tells me that the ? character is not a valid parameter name. If I put in a value instead of k, the report prints out what I need it to. I just can't seem to get the parameter part working.
Can you tell me what I am doing wrong?

I am a beginner at using SQL with the Data Report Designer. Any help would be much appreciated.
 
For Alan C (Data report designer)

Your code should be changed as follows:
DataEnvironment1.Codes_Grouping List1.List(list1.listIndex)
DeptReport_Detailed.Show

and to pass the parameter to your sql:
SELECT * FROM tbl_FaxData WHERE DatePart("m",[AcknowledgedTime])=?
Actually when you are in your data report design, select properties under your sqq(codes_grouping), the place where you see your SQL - under the 'General' tab - you can see your sql; then select 'Grouping' tab and then check mark 'group command object' and you must be able to see all the selected fields (in your case all the fields of that table as you have used '*') in the 'fields in command' and your grouping field in 'Fields used for grouping'; if this one looks ok, then select 'Parameters' tab and place and set the parameters properties - name, type etc., and place a ? in 'Parameters' box. As you are sending only one parameter, you do this once only. You can set as many parameters as you want but that number should match with the number of parameters (?) in your sql statement.
The sql should look similar to the following:
Select * FROM table a where lastname=?


I am not exactly sure about your datapart("m", ...
But I do not have any problems sending parameters to the report. If you want you could see my explanation on this topic on August 1 under 'uthamsar'. If you still need any clarifications, let me know.
 
Thanks for your quick response Uthamsar,

I am however still having some problems. Maybe I am not understanding how all of this works ... I don't want to group the report any further. The child command object where my SQL lies, is within the details section of a grouping. I dragged the one field in the Summary section of the grouping to the first group header of the report(DeptGrouping_Header), and used another field from the details of that grouping to the group header just below the DeptGrouping_Header (called Codes_Header). I then have a Details section just below Codes_Header on the report, and that is where I am trying to use the SQL statement to filter out the data I need.


I have tried adding the
DataEnvironment1.Codes_Grouping List1.List(List1.ListIndex)
but it still gives me the same error message:
Compile Error: Wrong number of arguments or invalid property assignment

I tried as you said selecting the 'Grouping' tab, and placing a check beside 'group command object', but then it tells me that at least one field must be used in the grouping. I then selected the 'AcknowledgedTime' field and selected OK. It then created another grouping under the Command object with the SQL in it (I think at this point I have gone too far because I don't need another grouping...) I dragged the 'AcknowledgedTime' field from the Summary of this grouping onto the details section of the report, but the same error occurs.

I feel that the structure of my DataEnvironment (with respect to groupings and child commands) is correct ... but that there's something else missing in the code ... please let me know if I am wrong.

Any further help would be much appreciated.
 
To Alan C:
if you do not mind could you send me your files (in a zipped file). my e-mail address is ravinuthala@un.org.
I used a grouping object and it was working finw for me. May be if I look into your code, I might be able to help you.
 
For Alan C:
Another quick check is in the following command
DataEnvironment1.Codes_Grouping List1.List(List1.ListIndex)
do instead this
DataEnvironment1.Codes_Grouping n
That n can be any valid number in your combo box.
If you are still getting that error check the parameter tab and lookfor the data type

Could you please check in the parameters (when you go into the properties of your command object, check the parameter tab)- the data type. If you are sending a number from your combo box and the data type is advarchar or something, then you would get an error. It should be changed to either adNumeric or adInteger. Try that and see.

I have feeling that this should work as you were saying that it was working if you hardcoded a number instead of k
 
I have a similar question regarding using stored procedures in data environment. Basically I have a query in Acces with a field name tranDate with criteria [param] How do I assign values to this in my data environment. When I try to do "where table.trandate = parameter", it places both [param] and parameter in my parameter list and then comes back saying "invalid name" for [param]. Also I tried table.tranDate[param] = parameter, but that sis not seem to work either. Any help ASAp would be greatly appreciated.
 
Hello
I have written a program to handle the printer specification and paper from vb programs . if you want the program source i can send it to you..
email address : rostami@scsco.net

but
 
To Gaurishankar

Under your connectionobject sql properties, select general tab; use SQl statement, for ex:
Select * from tablex where fieldname1=?
That question mark is important.
Then click parameter tab, you could see '?' under parameters, under 'paramater properties' typr param1, and select the data typr depending the type of parameter you are going to send (varchar , integer etc).

From your application, whatever event from where you want to run your report, grab the value you want to send it as the parameter ( for example when the user selected avalue ffrom a list box or combo box) and then do the following:
data
if codes is your command name in the data environment, datareport is your report name then
If DataEnvironment1.rscodes.State = adStateOpen Then
DataEnvironment1.rsCodes.Close
End If
DataEnvironment1.codes the value you grabbed (the one you want to send it as a parameter
Datareport.Show

If you prefer to send your code to me in a zipped file, you can do that, I am glad to help you out. My e-mail is ravinuthala@un.org
 
I am trying to bring data into a report from two different tables. I can bring both fields under the parent command but when I put it inside a report the application locks up and refuses to respnod. Any help would be greatly appreciated.
 
It is very difficult to understand what you are doing exactly. If you do not mind, semd me your code, I will look into the code. my e-mail address is Ravinuthala@un.org
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top