Link to home
Start Free TrialLog in
Avatar of asimoes
asimoes

asked on

VB6 Data REport designer

How can I send the content of a textbox to a report?
Imagine that a user needs to print a report of a certain client and  write in some field of a form the client number.
Then the report is printed with the data of that client.
I´m using VB6 with the data report designer and working with a database.

Thanks
Avatar of roverm
roverm
Flag of Netherlands image

Place a label on the DataReport, then before invoking it, change the Caption:

DataReport1.Section("Section").Controls("Label1").Caption = Text1.Text

Good Luck !

RoverM
Avatar of asimoes
asimoes

ASKER

I´m sorry but I need more than that.
I need to retrieve the record from that client from a table not just show it on the report.
I´m using Data environment with SQL instructions and commands.
And maybe in the SQL sentence I need to put a variable with the textbox content so it can then retrieve the records of that client.

Thanks again.
Ok, why don't u use parameters then, something like:

SELECT * FROM myTable WHERE clientname LIKE ?

Then, before invoking the DR:

DataEnvironment1.Connection1.comSQL Text1.Text

where comSQL is your sql statement

Then invoke the DR.

RoverM
Beware: the ? belongs to the sql statement !!!!!!
Avatar of asimoes

ASKER

Hello again
The code you gave me works fine.
But must I have a DataEnvironment "object" working?
How can I create a the equivalent solution but programaticly?
That is, create an environment,
 a command , and a datareport with the sections related to the command.
Becouse I've tried to make everything programaticly (commands,recordsets,assigning the datasource od the datareport to the recordset) but then I cannot control the sections of the datareport.

Thanks

Yes, you can do that through code, something like:

Dim cn As ADODB.Connection
Dim rs As ADODB.RecordSet

Set cn = New ADODB.Connection
cn.Open "some dsn name or stuff"
rs.Open "sql statement", cn

Then bind the recordset to the DR:

Set DataReport1.DataSource = rs

Then bind all of the TEXT fields to the recordset and so on !
Of course, you cannot drag & drop the fields on your DR because the DR 'doesn't know yet' which database/recordset to use. That's why it's easier to use the dataenv. !

Good luck !
Avatar of asimoes

ASKER

Hello Again
I've already tried what you wrote but the problem is:
When I trie to make a section group in the datareport to separate the information like this:
----header-----------
-----section (client)-----
Client number
------------section (invoices)----
invoice number  date  blablabla
-----------end section (invoices)---
                  sum(somefield)
---close section (client)----
----footer-------
Question:
When I add a section group in the datareport it gives the error telling the datareport does not corresponde with ....

Thanks
Yep, I know, that's why I don't like the DR !!!!!
However, if you want to see a really good example check out the MSDN libary, disc 1:
e:\samples\vb98\datarept (prjNwind.vbp)

This is an example which uses the DR very nice (but with the use of a dataenv!).

Your problem is that the DR doesn't understand 2 sections referring to the same datasource ! BUT you cannot assign 2 different datasources !!!! Nice huh ?

Check out the example, it uses multiple sections. It can use this by using a 'trick' in the dataenv. It groups and aggregates and adds command.....
See for yourself !

Good Luck !

RoverM
Avatar of asimoes

ASKER

A last and personal question.
What you use if you don´t use the Dataenv.?
The print object directly to the printer and make your own reports?

Thanks you so much for everything.

Alberto Simões
From Portugal
For every DataReport designer it is easier to use a DataEnvironment because then the DR 'knows' which field are there and you can drag & drop (ok, you can use the DataView window for drag & drop also...).
If you don't want to use a DR then use the printer object. But you have to calculate everything (the coordinates and stuff).

It can be done, but it is way easier to use a datareport.
Why don't u use a DataEnv. ? It's so easy ! Ok, there are a few bugs in there but heck, it's M$ !

Good Luck !

RoverM from The Netherlands
Ps: Portugal ? Is a nice land for holidays isn't it ? Where should I go, what should I visit ?
grtx, RoverM
Avatar of asimoes

ASKER

Well Portugal is a Historic country.
So where ever you go there's a lot of monuments to see and in the sommer the beach is the best place to be.
If you like summer and beach then you must go to Algarve in the south of Portugal.


Thanks again
ASKER CERTIFIED SOLUTION
Avatar of roverm
roverm
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial