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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Ado.Command to crystal report, but crystal still show olddata

Status
Not open for further replies.

pragash

Programmer
Aug 28, 2002
2
MY

My problem is i have function called preview report. When the user select a new contract and clicks on the button, the report should be updated with the new contract. But, it does not get updated with the new contract. It still shows
the old record.

I will show you my code and explain what i have done.

i am using crystal report 8.5 and VB 6.0

I am using

Function preview_Report()

Dim rsd As ADODB.Recordset
Dim rs_cmd As ADODB.Command
Dim query_temp As String
Dim test As String
Dim cp_no As Long
Dim dt As String

dt = ""
dt = built_date
'********************************************
'built_date Its a function to get the year and '
'month from the user and combined. Its a criteria that
'is used in the query
'*********************************************
cp_no = 0

cp_no = Combo1.Text
'**********************************************
'cp_no is the contract no that is selected by the user
'Used as a criteria in the query
'**********************************************

query_temp = ""
query_temp = " Select agency_name, agency_add, advertiser_name, advertiser_add, camp_no, "
query_temp = query_temp + " camp_origination_date, camp_pree_status, order_no, product_name, "
query_temp = query_temp + " camp_start_date, camp_end_date, spot_no, spot_duration, "
query_temp = query_temp + " spot_type, spot_air_date, brek_nom_time, prog_name, channel, "
query_temp = query_temp + " spot_code, spot_price, copy_code "
query_temp = query_temp + " From campaign_summary_direct Where camp_no = " & cp_no&
query_temp = query_temp + " And spot_air_date Like " + dt

'********************************
'query temp is the query that will be passed to
'Ado.command to be executed
'I have tested the query and i am very sure that
'its fine.
'***********************************


Set rs_cmd = New ADODB.Command
Set rsd = New ADODB.Recordset

on error goto x

'*************************************************
'on error go to x is need when the function is executed
'for the first time , because the rsd recordset is
'not opened,

'*************************************

rsd.close


x:

rsd.Open query_temp, cn_temp, adOpenForwardOnly, adLockReadOnly


Set rs_cmd.ActiveConnection = cn_temp
rs_cmd.CommandText = query_temp
rs_cmd.CommandType = adCmdText
Set rsd = rs_cmd.Execute(query_temp)

Bound_report
'*************************************
'Bound Report is a function set unbound fields. My report
' has unbound fields in it.
'I have checked and its Fine
'**************************************

Report1.Database.AddADOCommand cn_temp, rs_cmd
'cn_temp is the connections string defined and set
'during form load.


Form1.CRViewer1.ReportSource = Report1
Report1.ReadRecords
Report1.DiscardSavedData
Form1.CRViewer1.ViewReport
Form1.Show

End Function


Further explanation

I am very sure that the query is executed with different criteria. so this cannot be the reason why the report is
not being updated. What happens is when i first start my program, i select the contract no = 1000 and the report gets updated with ccontact 1000. then lets say i select
contract 1200 , the report still shows me contract 1000.

any subsequent execution of preview report function shows me contract 1000. So only the first attempt , right after i start the program shows me the correct contract.

i have used Report1.DiscardSavedData to remove saved data, if there is any.(Does not work)

I have used Report1.ReadRecords to force it to update the data in the report from the ADO.command,(Does not work).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top