DAO and Data Report 6


I am trying to figure out the Data Report 6 in VB6. I have an app that uses DAO to handle data acquisition and modification. I want to be able to print reports based upon a SQL statement that is determined at runtime and am having no little confusion in figuring out how to pass a SQL statement as the datasource with Data Reports 6. Could someone please tell me what code is necessary to set at runtime and where it should be placed? I know I need the Data environment first and then the data report. I'm assuming the Data Environment is where the SQL is passed, but how?

Who is Participating?
ah_sinConnect With a Mentor Commented:
I hope my answer won't be too late

I think you are looking for a way to change your sql statement during run-time... if i get your question right, you may want to try this

DE - data environment
comTemp - command object in DE
(set a simple SQL statement in the property window of comTemp)
drTest - data report object
*connect the dataSource property of drTest to DE
*connect the dataMember property of drTest to comTemp
*on drTest... you got the fields you need in the data report (on right places)

set the SQL statement as following in the code

DE.Commands("comTemp").CommandText = _
       "<Your new query statement>"
DE.rscomTemp.Requery      'This line let you to "renew" your

See if this work :)
ah sin
Just a small hint
I use crystal reports rather than Report writer 6 because i found the report writer with vb6 is very limiting.
goto this site www.seagatesoftware.com and download the freee version of crystal 6.
it plugs directly inot vb. Whay i do is if i want to create a report dynamically i have my sql set up and when the user click s a button i run my sql statement and populate a temporary table and then open the report. At design time i point the report to the temporary table. So at run time the report displays the inforamtion that the sql statement executed.

Just thought it might help if u do not come write with th report writer

kenb030297Author Commented:
Thanks Craig ... I have CR6 but was never able to make head nor tail of how to work it. Your suggestion of a temporary table makes a lot of sense though ... I'll give it a shot. Thanks.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

no problem
Ken just install Crustal 6 then go Project ---> Add Activex Manager then u should see Crystal 6 there.

Run Crystal and go thru the wixard of creating a standard report. It will ask u what project u wnat to connect to (being your database) then it auto fetche the tables from that database. then select the table u want to referenece (your TmpTable) than it picks up auto the fields belonging to that table. Then u go thru the standard steps of adding fields onto the report. the wizard does everything for you. Once done u can change the design add fields etc. What is great is that it plugs and the reports are combined into the apps exe file. The previous versions of crystal 4.6(shipped with vb5,vb4) u had to distribute the report files along with the exe file. Which used to get messy.

anyway if that helps .
Also i left out in my comment earlier is that whenever the user runs the dynamic report, i first delete all the records in the temp table before i write into it with the new records as to make sure the data is correct and valid
if this makes any sense :0)


kenb030297Author Commented:
Thanks for your help ah_sin,

Your suggestion would work if I had not gone another direction. Since posting this question I changed my entire app to use ADO, decided against the Data Environment and just created several Data Reports which I populate entirely by code. It would be much nicer if MS allowed us to address a control more like they do in VB but with some practice and LOTS of comments, I have managed to locate each control numerically as well as the datafields they are populated by.
so you find ADO easier to use?
I know nothing about ADO :(
I should have try that too
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.