SQL query at runtime using CR

Davos
01-13-2004, 05:56 AM
I have this CR with what I believe is a built-in sql query in the VB designer. When I run it the report loads fine. However when I try to run a query at run time as per:


adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS


The VB IDE crashes. How can I cancel this built in query so I can use queries at runtime?

I some CR smaples I got with the CR programme when I right-click over Database Fields in the panel on the LHS, I don't see 'Show SQL Query'. It's there in my project. I believe this is what is confusing the IDE as it is expecting to only run the query in there. I want to run a query at run-time and cancel this query. How do I do that? Many thanks.

MKoslof
01-13-2004, 06:35 AM
What do you mean "built in" query? Where is this called? Can you post all your relevant code..is this a piece of code that is populating a report, or a recordset, or both?

You say the report loads fine, but then the VBE crashes...this is kind of confusing..where is this query being executed?

Davos
01-13-2004, 06:41 AM
Hi,

Thanks for responding.

Ok, what I mean is I used the databse expert to build a relationship between fields in a dsr file and fields in a database. I simply have 7 fields linked. When I call the report as per the code below it works fine:

Dim datcmd1 As ADODB.Command
Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

Set datcmd1 = New ADODB.Command
Set datcmd1.ActiveConnection = myDbCon
Set frmDet = New CrystRepForm

datcmd1.CommandText = "CRCustInvMain"
datcmd1.CommandType = adCmdTable

InvM.DiscardSavedData
InvM.Database.AddADOCommand myDbCon, datcmd1

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set datcmd1 = Nothing
Set frmDet = Nothing

However when I try to call this code the ide crashes:

Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing

Any ideas what I am missing?

What do you mean "built in" query? Where is this called? Can you post all your relevant code..is this a piece of code that is populating a report, or a recordset, or both?

You say the report loads fine, but then the VBE crashes...this is kind of confusing..where is this query being executed?

MKoslof
01-13-2004, 07:00 AM
why do you have two seperate pieces of code here? Basically on the CRViewer form load event you should declare a new instance of the dsr file, open your connection and recordset, disgardsaved data and use SetDataSource to bind a new recordset to the dsr and then continue with CRViewer code...why do you have two seperate procedures for populating a single report?

Davos
01-13-2004, 08:36 AM
Hi,

It's two methods, because the first one works and the second one does not. I'm trying to use the 2nd and only this one but it does not work.

I seem to be doing exactly what you suggest here with the 2nd bit of code but the programme crashes.

Any further ideas, MKoslof? Many thanks.

why do you have two seperate pieces of code here? Basically on the CRViewer form load event you should declare a new instance of the dsr file, open your connection and recordset, disgardsaved data and use SetDataSource to bind a new recordset to the dsr and then continue with CRViewer code...why do you have two seperate procedures for populating a single report?

Davos
01-13-2004, 08:39 AM
I'm inclusing a screenshot of the dsr part.

Hi,

It's two methods, because the first one works and the second one does not. I'm trying to use the 2nd and only this one but it does not work.

I seem to be doing exactly what you suggest here with the 2nd bit of code but the programme crashes.

Any further ideas, MKoslof? Many thanks.

why do you have two seperate pieces of code here? Basically on the CRViewer form load event you should declare a new instance of the dsr file, open your connection and recordset, disgardsaved data and use SetDataSource to bind a new recordset to the dsr and then continue with CRViewer code...why do you have two seperate procedures for populating a single report?

Davos
01-13-2004, 08:42 AM
The file again.

I'm inclusing a screenshot of the dsr part.

Hi,

It's two methods, because the first one works and the second one does not. I'm trying to use the 2nd and only this one but it does not work.

I seem to be doing exactly what you suggest here with the 2nd bit of code but the programme crashes.

Any further ideas, MKoslof? Many thanks.

why do you have two seperate pieces of code here? Basically on the CRViewer form load event you should declare a new instance of the dsr file, open your connection and recordset, disgardsaved data and use SetDataSource to bind a new recordset to the dsr and then continue with CRViewer code...why do you have two seperate procedures for populating a single report?

MKoslof
01-13-2004, 09:30 AM
No, I never told you to do anything like this :).
When does this first procedure run...and when does the second procedure run...
there are many inconsistensies here.

-your first piece of code



Dim datcmd1 As ADODB.Command
Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

Set datcmd1 = New ADODB.Command
Set datcmd1.ActiveConnection = myDbCon
Set frmDet = New CrystRepForm

datcmd1.CommandText = "CRCustInvMain"
datcmd1.CommandType = adCmdTable

InvM.DiscardSavedData
InvM.Database.AddADOCommand myDbCon, datcmd1

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set datcmd1 = Nothing
Set frmDet = Nothing



so what command are you passing to the report's database? what is myDbcon, what connection is this?
Instead of using a .commandText call you much better off just using a recordset.open event.

What is loadMe = True? What is this for?
You can use the .readRecords method, but you shouldn't use it with the SetDataSource method
you use both in your next code piece. So when does this code piece run?


-your second code piece (why do you have two events with COMPLETELY different methods?)


Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing



-as I stated before, you don't need readrecords after using the SetDataSource command. And be
consistent, here you are trying to use a recordset.open event and in the other procedure you're
not.

-Also what fields are on your report..you CAN'T do it like this. First you are assigning all
the fields in the table "CRCustInvMain" to the report..then you want to change the table
completely and use completely different fields? Are the fields on both tables the same?
And what fields are on the report AT DESIGN TIME. If you trying to pass fields not on the
report, or are trying to use a different table with different fields, this won't work.

-What is your database connection type? (Access, Oracle, SQL). You need to restructure this
so your data integrity is enforced. The report was designed with fields from a table. You
can't force the report to use fields not on the report and if you want dynamic tables, the
tables must be structurally similiar.

Davos
01-13-2004, 09:33 AM
But, As I said these two procedures do not run together. The fisrt one ifs the old one I was using. The 2nd is the new one I want to use using a recordset.

I am reading your post more closely and will be back in a sec.

Thanks.

No, I never told you to do anything like this :).
When does this first procedure run...and when does the second procedure run...
there are many inconsistensies here.

-your first piece of code



Dim datcmd1 As ADODB.Command
Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

Set datcmd1 = New ADODB.Command
Set datcmd1.ActiveConnection = myDbCon
Set frmDet = New CrystRepForm

datcmd1.CommandText = "CRCustInvMain"
datcmd1.CommandType = adCmdTable

InvM.DiscardSavedData
InvM.Database.AddADOCommand myDbCon, datcmd1

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set datcmd1 = Nothing
Set frmDet = Nothing



so what command are you passing to the report's database? what is myDbcon, what connection is this?
Instead of using a .commandText call you much better off just using a recordset.open event.

What is loadMe = True? What is this for?
You can use the .readRecords method, but you shouldn't use it with the SetDataSource method
you use both in your next code piece. So when does this code piece run?


-your second code piece (why do you have two events with COMPLETELY different methods?)


Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing



-as I stated before, you don't need readrecords after using the SetDataSource command. And be
consistent, here you are trying to use a recordset.open event and in the other procedure you're
not.

-Also what fields are on your report..you CAN'T do it like this. First you are assigning all
the fields in the table "CRCustInvMain" to the report..then you want to change the table
completely and use completely different fields? Are the fields on both tables the same?
And what fields are on the report AT DESIGN TIME. If you trying to pass fields not on the
report, or are trying to use a different table with different fields, this won't work.

-What is your database connection type? (Access, Oracle, SQL). You need to restructure this
so your data integrity is enforced. The report was designed with fields from a table. You
can't force the report to use fields not on the report and if you want dynamic tables, the
tables must be structurally similiar.

MKoslof
01-13-2004, 09:37 AM
when the procedures run is irrelevant. What matters is you are first assigning all records from one table, and then in a seperate procedure, you are attempting to assign multiple records from a completely different table.

Whatever fields are assigned on the report need to keep data integrity..and the table that the report was DESIGNED to use is still in memory..if you try to change tables the field structures need to be comparable or the report will crash..it can not assign field values if the fields are not present on the report.

Davos
01-13-2004, 09:43 AM
To answer your questions, in large caps:

so what command are you passing to the report's database?I JUST WANT TO CREATE A RECORDSET. THE COMMAND PART I WAS USING IN THE FIRST BIT OF CODE MIGHT HAVE BEEN UNCESSARY AS YOU SEEM TO POINT OUT. IT WAS JUST A TABLE WITH 7 COLUMNS TO BE READ USING 7 FILDS ON A REPORT. BUT THAT'S HOW I HAD IT BEORE. NOW, I WANT TO USE A RECORDSET. what is myDbcon, what connection is this?
Instead of using a .commandText call you much better off just using a recordset.open event.

What is loadMe = True? What is this for? NOTHING, JUST SOME FLAG NOT RELEVANT TO WHAT WE'RE DOING HERE.
You can use the .readRecords method, but you shouldn't use it with the SetDataSource method OK
you use both in your next code piece. So when does this code piece run? SEE PREVIOUS POST.


-your second code piece (why do you have two events with COMPLETELY different methods?) SEE PREVIOUS POST.


Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing



-as I stated before, you don't need readrecords after using the SetDataSource command. OK And be
consistent, here you are trying to use a recordset.open event and in the other procedure you're
not.

-Also what fields are on your report..you CAN'T do it like this. SEE SCREENSHOT. First you are assigning all
the fields in the table "CRCustInvMain" to the report..then you want to change the table
completely and use completely different fields? Are the fields on both tables the same? IT'S ONE TABLE WITH 7 COLUMNS. IN THE NEW METHOD I ADDED 'Cust_Nber' TO CALL UP RECORDS FOR EACH CUSTOMER.
And what fields are on the report AT DESIGN TIME. SEE SCREENSHOT. If you trying to pass fields not on the
report, or are trying to use a different table with different fields, this won't work. THE REPORT DESIGN HAS NOT CHANGED SINCE I JUST WANT TO POPULATE A CUSTOMER TABLE WITH DATA FOR ALL CUSTOMERS THEN CALL UP THE DATA FOR EACH CUSTOMER SPEARATELY. BEFORE I HAD A KIND OF TEMPORARY TABLE THAT I DELETED AND POPULATED FOR EACH CUSTOMER.

-What is your database connection type? (Access, Oracle, SQL). IT'S ACCESS You need to restructure this
so your data integrity is enforced. The report was designed with fields from a table. You
can't force the report to use fields not on the report and if you want dynamic tables, the
tables must be structurally similiar. THE DATA IS THE SAME, ONLY THIS 'Cust_Nber' FIELD WAS ADDED TO DISCREMNATE THE DATA ACCORDING TO THE CUSTOMER. MANY THANKS.[/QUOTEPOST][/QUOTEPOST]

Davos
01-13-2004, 09:49 AM
HI,

Yes. You are right. I got my business mixed up here. 'Ve staring at that screen too long. It works fine now. Like you say I was using a different table between the two methods, hence the problems I've had.

It works fine.

I owe you a drink MKoslof.

A million thanks.

Davos.

To answer your questions, in large caps:

so what command are you passing to the report's database?I JUST WANT TO CREATE A RECORDSET. THE COMMAND PART I WAS USING IN THE FIRST BIT OF CODE MIGHT HAVE BEEN UNCESSARY AS YOU SEEM TO POINT OUT. IT WAS JUST A TABLE WITH 7 COLUMNS TO BE READ USING 7 FILDS ON A REPORT. BUT THAT'S HOW I HAD IT BEORE. NOW, I WANT TO USE A RECORDSET. what is myDbcon, what connection is this?
Instead of using a .commandText call you much better off just using a recordset.open event.

What is loadMe = True? What is this for? NOTHING, JUST SOME FLAG NOT RELEVANT TO WHAT WE'RE DOING HERE.
You can use the .readRecords method, but you shouldn't use it with the SetDataSource method OK
you use both in your next code piece. So when does this code piece run? SEE PREVIOUS POST.


-your second code piece (why do you have two events with COMPLETELY different methods?) SEE PREVIOUS POST.


Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing



-as I stated before, you don't need readrecords after using the SetDataSource command. OK And be
consistent, here you are trying to use a recordset.open event and in the other procedure you're
not.

-Also what fields are on your report..you CAN'T do it like this. SEE SCREENSHOT. First you are assigning all
the fields in the table "CRCustInvMain" to the report..then you want to change the table
completely and use completely different fields? Are the fields on both tables the same? IT'S ONE TABLE WITH 7 COLUMNS. IN THE NEW METHOD I ADDED 'Cust_Nber' TO CALL UP RECORDS FOR EACH CUSTOMER.
And what fields are on the report AT DESIGN TIME. SEE SCREENSHOT. If you trying to pass fields not on the
report, or are trying to use a different table with different fields, this won't work. THE REPORT DESIGN HAS NOT CHANGED SINCE I JUST WANT TO POPULATE A CUSTOMER TABLE WITH DATA FOR ALL CUSTOMERS THEN CALL UP THE DATA FOR EACH CUSTOMER SPEARATELY. BEFORE I HAD A KIND OF TEMPORARY TABLE THAT I DELETED AND POPULATED FOR EACH CUSTOMER.

-What is your database connection type? (Access, Oracle, SQL). IT'S ACCESS You need to restructure this
so your data integrity is enforced. The report was designed with fields from a table. You
can't force the report to use fields not on the report and if you want dynamic tables, the
tables must be structurally similiar. THE DATA IS THE SAME, ONLY THIS 'Cust_Nber' FIELD WAS ADDED TO DISCREMNATE THE DATA ACCORDING TO THE CUSTOMER. MANY THANKS.[/QUOTEPOST][/QUOTEPOST]

MKoslof
01-13-2004, 09:51 AM
Glad you got it to work...Good luck!

Davos
01-13-2004, 09:57 AM
One last question.

I am using in this report called InvM, a subreport. How can I pass it a recordset from table CRCustomerInv, whilst using table CRCustInvMain to build the main report?

Many thanks.

HI,

Yes. You are right. I got my business mixed up here. 'Ve staring at that screen too long. It works fine now. Like you say I was using a different table between the two methods, hence the problems I've had.

It works fine.

I owe you a drink MKoslof.

A million thanks.

Davos.

To answer your questions, in large caps:

so what command are you passing to the report's database?I JUST WANT TO CREATE A RECORDSET. THE COMMAND PART I WAS USING IN THE FIRST BIT OF CODE MIGHT HAVE BEEN UNCESSARY AS YOU SEEM TO POINT OUT. IT WAS JUST A TABLE WITH 7 COLUMNS TO BE READ USING 7 FILDS ON A REPORT. BUT THAT'S HOW I HAD IT BEORE. NOW, I WANT TO USE A RECORDSET. what is myDbcon, what connection is this?
Instead of using a .commandText call you much better off just using a recordset.open event.

What is loadMe = True? What is this for? NOTHING, JUST SOME FLAG NOT RELEVANT TO WHAT WE'RE DOING HERE.
You can use the .readRecords method, but you shouldn't use it with the SetDataSource method OK
you use both in your next code piece. So when does this code piece run? SEE PREVIOUS POST.


-your second code piece (why do you have two events with COMPLETELY different methods?) SEE PREVIOUS POST.


Dim frmDet As CrystRepForm

On Error GoTo ErrTrap

Set adoRS = New ADODB.Recordset

adoRS.Open "SELECT Nber_Calling, Call_Destination, Nbr_Called, Date_Time_Called, Call_Duration, Call_Cost, Call_Type " & _
"FROM CRCustomerInv WHERE Cust_Nber = '" & custData(0) & "'", myDbCon, adOpenDynamic, adLockBatchOptimistic
InvM.Database.SetDataSource adoRS

InvM.ReadRecords
loadMe = True
frmDet.Show vbModeless, Me
frmDet.CRViewer91.ReportSource = InvM
frmDet.CRViewer91.ViewReport
Call WaitTimer(3)
frmDet.CRViewer91.Refresh

Set adoRS = Nothing



-as I stated before, you don't need readrecords after using the SetDataSource command. OK And be
consistent, here you are trying to use a recordset.open event and in the other procedure you're
not.

-Also what fields are on your report..you CAN'T do it like this. SEE SCREENSHOT. First you are assigning all
the fields in the table "CRCustInvMain" to the report..then you want to change the table
completely and use completely different fields? Are the fields on both tables the same? IT'S ONE TABLE WITH 7 COLUMNS. IN THE NEW METHOD I ADDED 'Cust_Nber' TO CALL UP RECORDS FOR EACH CUSTOMER.
And what fields are on the report AT DESIGN TIME. SEE SCREENSHOT. If you trying to pass fields not on the
report, or are trying to use a different table with different fields, this won't work. THE REPORT DESIGN HAS NOT CHANGED SINCE I JUST WANT TO POPULATE A CUSTOMER TABLE WITH DATA FOR ALL CUSTOMERS THEN CALL UP THE DATA FOR EACH CUSTOMER SPEARATELY. BEFORE I HAD A KIND OF TEMPORARY TABLE THAT I DELETED AND POPULATED FOR EACH CUSTOMER.

-What is your database connection type? (Access, Oracle, SQL). IT'S ACCESS You need to restructure this
so your data integrity is enforced. The report was designed with fields from a table. You
can't force the report to use fields not on the report and if you want dynamic tables, the
tables must be structurally similiar. THE DATA IS THE SAME, ONLY THIS 'Cust_Nber' FIELD WAS ADDED TO DISCREMNATE THE DATA ACCORDING TO THE CUSTOMER. MANY THANKS.[/QUOTEPOST][/QUOTEPOST]

MKoslof
01-13-2004, 10:08 AM
You can use the set datasource method..but assign it to the subreport,
which I assume has its own name. So, instead of opening a recordset and assigning it to the Main report...assign it to the sub report.
But the same data integrity rules apply, but a sub-report is independant of its parent (in terms of allowing a different table) then this recordset can be passed with basically the same method.

Just create an instance of the subreport like this:


'pass in an instance of the subreport on the dsr
set aSubrep = report.opensubreport (subreport1.subreportname)



then use the same events and commands that you used to populate the main report to populate this report. But remember any links between the two reports still need to be enforced.

Davos
01-13-2004, 10:21 AM
Thanks again for all the help! I'm still new to all this CR stuff. It's interesting though. Cheers.

You can use the set datasource method..but assign it to the subreport,
which I assume has its own name. So, instead of opening a recordset and assigning it to the Main report...assign it to the sub report.
But the same data integrity rules apply, but a sub-report is independant of its parent (in terms of allowing a different table) then this recordset can be passed with basically the same method.

Just create an instance of the subreport like this:


'pass in an instance of the subreport on the dsr
set aSubrep = report.opensubreport (subreport1.subreportname)



then use the same events and commands that you used to populate the main report to populate this report. But remember any links between the two reports still need to be enforced.

MKoslof
01-13-2004, 10:34 AM
.dsrs are quite easy to use once you understand the basics of them. They provide some very handy tools NOT available when trying to use natve .rpt files such as unbound string and integer fields.

Davos
01-13-2004, 10:56 AM
Hi,

Am running the code. It seems it loads my viewer fine for each customer's invoice (the programme creates invoices) but when I try to go to the oter pages or export, it it saves the last report that was created. The programme goes in a loop and creates a report for each invoice then loads a modeless form for each of them. Would you know what is causing the reports to be discarded like this and why only the last one seems to be saved ?

Cheers again.

.dsrs are quite easy to use once you understand the basics of them. They provide some very handy tools NOT available when trying to use natve .rpt files such as unbound string and integer fields.

MKoslof
01-13-2004, 11:09 AM
What do you mean only the last one is saved? How many times are you creating the report? If I load a report, the datasource I give it during the form load (the code you are using, where it is called the form load, a module, etc.) will be passed then the CRViewer loads with that data.

The data will only change on each occurance that you run the code. Or maybe I don't understand the question. In your code, everytime you run the code, you set a new datasource and disgard the saved data

Davos
01-13-2004, 11:13 AM
Yes that might explain it. The modeless windows load the customer data correctly. However when I try and export each report using the export button, it saves the last report that was loaded on disk, and not the data that was loaded in my loop for ea. customer. The same happens when I click the 'more pages' button and skid from page to page. The report suddenly reverts to the last one we created. You can see the data physically change on screen from the one it should be to the data of the last customer. Thanks.

What do you mean only the last one is saved? How many times are you creating the report? If I load a report, the datasource I give it during the form load (the code you are using, where it is called the form load, a module, etc.) will be passed then the CRViewer loads with that data.

The data will only change on each occurance that you run the code. Or maybe I don't understand the question. In your code, everytime you run the code, you set a new datasource and disgard the saved data

MKoslof
01-13-2004, 11:23 AM
hmm..yes, it appears you may need to tweak your overall structure. What you probably want to do is load a NEW report instance for each customer..because the datasource call will effect the inital load event since that is where the new datasource is being populated. With a little restructuring, you can get this to work..but the overall flow of data is still correct.

Davos
01-13-2004, 11:26 AM
I know it's becoming a bit of a marathon, but thanks for your help again.

So I have been trying another part of my code where I save on disk each invoice using the ExportOptions. The files are saved correctly here. It seems I then only get that problem when trying to load the data in the viewer.

Any thought on this?

MKoslof
01-13-2004, 11:29 AM
OK, where is this code, in the form load event or in a seperate module. You may try running this code within a seperate module..so the form load event isn't calling it. I am not sure if you can accomplish what you want via the CRViewer..because each time the CRViewer loads it is a new instance....

I have to take care of some things here at work...but I'll be around. Feel free to send me a private message if this continues...but your overall goal may not be possible because of how the CRViewer handles its events

Davos
01-13-2004, 11:32 AM
Hi,

The code is in a module. Am trying what you suggested about creating a new instance of the report for each invoice.

OK, where is this code, in the form load event or in a seperate module. You may try running this code within a seperate module..so the form load event isn't calling it. I am not sure if you can accomplish what you want via the CRViewer..because each time the CRViewer loads it is a new instance....

I have to take care of some things here at work...but I'll be around. Feel free to send me a private message if this continues...but your overall goal may not be possible because of how the CRViewer handles its events

MKoslof
01-13-2004, 11:37 AM
basically the user selects something..then run the code to create the report...view that individual report. The user then closes out the report. Then another report is selected, the data for THAT report is loaded and the CRViewer loads with the new data.

If I understand correctly, the code to set the datasource only runs ONCE...but then you loop multiple instances of the CRViewer to load different reports..but the code to physically set the datasource has only run once and you are opening multiple instances of the CRViewer..this is the cause :).

Davos
01-13-2004, 11:44 AM
The code works like this:

I run a scan in a directory on my hdd that loads files and picks out information from there then loads the info into a listview. The information is then saved into a table and each line is marked with the number of the customer. Then the programme can either open the invoice, save on disk or print depending on the options the user set when he launched the run. Once this is done, the programme goes down another listview to the next customer and so on.

The code that sets the datasource is run each time it goes through this loop to load/save/print each invoice. The invoices load up in memory as modeless forms. The code runs as many times as there are customers (hundreds of times potentially).

basically the user selects something..then run the code to create the report...view that individual report. The user then closes out the report. Then another report is selected, the data for THAT report is loaded and the CRViewer loads with the new data.

If I understand correctly, the code to set the datasource only runs ONCE...but then you loop multiple instances of the CRViewer to load different reports..but the code to physically set the datasource has only run once and you are opening multiple instances of the CRViewer..this is the cause :).

MKoslof
01-13-2004, 12:30 PM
if you take out the CRViewer code and just use the .printout method do the reports print out with the proper data? When you run the code, before setting the new datasource you are using the .disgardsavedData command correct?

Davos
01-13-2004, 12:45 PM
Yes, the data prints correctly. I also use the disgardsavedData. Seems ok now I must say. Am still testing/debugging.

if you take out the CRViewer code and just use the .printout method do the reports print out with the proper data? When you run the code, before setting the new datasource you are using the .disgardsavedData command correct?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum