howesd
asked on
DataReport does not pick up updated values
I have an application that uses ADO to connect to an Access database and there are a number of forms which are used to update the database. The application also has a reporting subsystem which uses a DataEnviromnent and a number of DataReport objects. The problem is, my reports do not reflect the changes that are made in the updating forms until the application i closed and restarted. I create an ADO connection before each SQL statement in the forms and close it and set it to Nothing imediately afterwards to ensure that my udpates are being flushed to the database but I don't seem to have the same level of control over the DataEnvironments connection. I'm assuming that the problem is cache related, so I'm trying the flash the connections cache by using the JetEngine.refreshCache method. This works until I unload the form which calls the reports and then go back in to it at which point I get a runtime error "3709 - The connection cannot be used to perform this operation. It is either closed or invalid in this context" as I try to refresh the cache.
The relevant bits of code are as follows :
the load procedure of the entire application:
Private Sub Form_Load()
Dim db As String
On Error GoTo frmTopLevel_formload_error
Dim ini As New ProfileReader
'Dim sDbPath As String
Dim sDefaultDbPath As String
sDefaultDbPath = App.Path + "\data\saltcam.mdb"
ini.ProfileSection = "General"
ini.ProfileKeyword = "DBLocation"
ini.ProfileDefault = sDefaultDbPath
ini.IniFileName = App.Path & "\saltcam.ini"
gdb = ini.GetPropertyString
ini.ProfileKeyword = "HelpPath"
sHelpPath = ini.GetPropertyString
DataEnvironment1.Connectio n1 = gdb
Exit Sub
The load proc of the report form :
Private Sub Form_Load()
Dim i As Integer
Dim fred As New JRO.JetEngine
If DataEnvironment1.Connectio n1.State = adStateOpen Then
fred.RefreshCache DataEnvironment1.Connectio n1
End If
optDestination(0).Value = True
optDestination(1).Value = False
ReportArray(0).ReportLiter al = "Prioritised Waiting List"
ReportArray(1).ReportLiter al = "Review List"
ReportArray(2).ReportLiter al = "Caseload Totals"
ReportArray(3).ReportLiter al = "Analysis of Waiting Times"
ReportArray(4).ReportLiter al = "Active Caseload sorted by Status"
ReportArray(5).ReportLiter al = "School Age children on caseload sorted by school"
ReportArray(6).ReportLiter al = "Active Caseload sorted alphabetically"
ReportArray(7).ReportLiter al = "Waiting List sorted by Primary Need"
ReportArray(8).ReportLiter al = "Waiting List sorted by Time Waited"
For i = 0 To ReportArrayLength - 1
optReport(i).Caption = ReportArray(i).ReportLiter al
Next
Set fred = Nothing
End Sub
The code which submits the report :
Private Sub cmdReport_Click()
Dim i As Integer
Dim s As String
Dim bcontinue As Boolean
On Error GoTo cmdReport_Error
i = 0
While optReport(i).Value = False
i = i + 1
Wend
If optDestination(0).Value Then
Select Case i
Case cnstPrioritisedWaitingList
SetUpPrioritisedWaitingLis t PrioritisedWaitingList
Set frmPrintScheduler.rep = PrioritisedWaitingList
Case cnstreview_list
Set frmPrintScheduler.rep = review_list
Case cnstStatusTotals
Set frmPrintScheduler.rep = StatusTotals
Case cnstMonthlySummary
bcontinue = SetUpMonthlySummaryOfWaiti ngTimeCall (MonthlySu mmaryofwai tingtime)
If bcontinue Then
Set frmPrintScheduler.rep = MonthlySummaryofwaitingtim e
Else
Exit Sub
End If
Case cnstcaseload_status
Set frmPrintScheduler.rep = caseload_status
Case cnstcaseloadbyschool
Set frmPrintScheduler.rep = caseloadbyschool
Case cnstalphabetical_caseload
Set frmPrintScheduler.rep = alphabetical_caseload
Case cnstWaitingListByNeed
Set frmPrintScheduler.rep = WaitingListByNeed
Case cnstWaitingListByTimeWaite d
Set frmPrintScheduler.rep = WaitingListByTimeWaited
Case Else
Err.Raise 51001, "Reports Engine", "Unidentified Report Requested - Report Array Member " & i
End Select
frmPrintScheduler.Show vbModal
Else
Select Case i
Case cnstPrioritisedWaitingList
SetUpPrioritisedWaitingLis t PrioritisedWaitingList
PrioritisedWaitingList.Sho w vbModal
Case cnstreview_list
review_list.Show vbModal
Case cnstStatusTotals
StatusTotals.Show vbModal
Case cnstMonthlySummary
bcontinue = SetUpMonthlySummaryOfWaiti ngTimeCall (MonthlySu mmaryofwai tingtime)
If bcontinue Then
MonthlySummaryofwaitingtim e.Show vbModal
Else
Exit Sub
End If
Case cnstcaseload_status
caseload_status.Show vbModal
Case cnstcaseloadbyschool
caseloadbyschool.Show vbModal
Case cnstalphabetical_caseload
alphabetical_caseload.Show vbModal
Case cnstWaitingListByNeed
WaitingListByNeed.Show vbModal
Case cnstWaitingListByTimeWaite d
WaitingListByTimeWaited.Sh ow vbModal
Case Else
Err.Raise 51001, "Reports Engine", "Unidentified Report Requested - Report Array Member " & i
End Select
End If
Exit Sub
cmdReport_Error:
FatalError
End Sub
The code which actually runs the report
Private dd As DataReport
Private bPrintingFinished As Boolean
Property Set rep(d As DataReport)
Set dd = d
End Property
Private Sub Command1_Click()
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer2_Timer()
dd.PrintReport False, rptRangeAllPages
Timer2.Interval = 0
While dd.AsyncCount > 0
DoEvents
Wend
Unload dd
Set dd = Nothing
Unload Me
I am absolutely stuck with this - I have a suspicion that if I were to get rid of the data environment altogether and use ADO recordsets then my problem would go away, but if there is an easy way to get it to work without doing all that work, I'd prefer to do it.
Thanks in advance
Dave
The relevant bits of code are as follows :
the load procedure of the entire application:
Private Sub Form_Load()
Dim db As String
On Error GoTo frmTopLevel_formload_error
Dim ini As New ProfileReader
'Dim sDbPath As String
Dim sDefaultDbPath As String
sDefaultDbPath = App.Path + "\data\saltcam.mdb"
ini.ProfileSection = "General"
ini.ProfileKeyword = "DBLocation"
ini.ProfileDefault = sDefaultDbPath
ini.IniFileName = App.Path & "\saltcam.ini"
gdb = ini.GetPropertyString
ini.ProfileKeyword = "HelpPath"
sHelpPath = ini.GetPropertyString
DataEnvironment1.Connectio
Exit Sub
The load proc of the report form :
Private Sub Form_Load()
Dim i As Integer
Dim fred As New JRO.JetEngine
If DataEnvironment1.Connectio
fred.RefreshCache DataEnvironment1.Connectio
End If
optDestination(0).Value = True
optDestination(1).Value = False
ReportArray(0).ReportLiter
ReportArray(1).ReportLiter
ReportArray(2).ReportLiter
ReportArray(3).ReportLiter
ReportArray(4).ReportLiter
ReportArray(5).ReportLiter
ReportArray(6).ReportLiter
ReportArray(7).ReportLiter
ReportArray(8).ReportLiter
For i = 0 To ReportArrayLength - 1
optReport(i).Caption = ReportArray(i).ReportLiter
Next
Set fred = Nothing
End Sub
The code which submits the report :
Private Sub cmdReport_Click()
Dim i As Integer
Dim s As String
Dim bcontinue As Boolean
On Error GoTo cmdReport_Error
i = 0
While optReport(i).Value = False
i = i + 1
Wend
If optDestination(0).Value Then
Select Case i
Case cnstPrioritisedWaitingList
SetUpPrioritisedWaitingLis
Set frmPrintScheduler.rep = PrioritisedWaitingList
Case cnstreview_list
Set frmPrintScheduler.rep = review_list
Case cnstStatusTotals
Set frmPrintScheduler.rep = StatusTotals
Case cnstMonthlySummary
bcontinue = SetUpMonthlySummaryOfWaiti
If bcontinue Then
Set frmPrintScheduler.rep = MonthlySummaryofwaitingtim
Else
Exit Sub
End If
Case cnstcaseload_status
Set frmPrintScheduler.rep = caseload_status
Case cnstcaseloadbyschool
Set frmPrintScheduler.rep = caseloadbyschool
Case cnstalphabetical_caseload
Set frmPrintScheduler.rep = alphabetical_caseload
Case cnstWaitingListByNeed
Set frmPrintScheduler.rep = WaitingListByNeed
Case cnstWaitingListByTimeWaite
Set frmPrintScheduler.rep = WaitingListByTimeWaited
Case Else
Err.Raise 51001, "Reports Engine", "Unidentified Report Requested - Report Array Member " & i
End Select
frmPrintScheduler.Show vbModal
Else
Select Case i
Case cnstPrioritisedWaitingList
SetUpPrioritisedWaitingLis
PrioritisedWaitingList.Sho
Case cnstreview_list
review_list.Show vbModal
Case cnstStatusTotals
StatusTotals.Show vbModal
Case cnstMonthlySummary
bcontinue = SetUpMonthlySummaryOfWaiti
If bcontinue Then
MonthlySummaryofwaitingtim
Else
Exit Sub
End If
Case cnstcaseload_status
caseload_status.Show vbModal
Case cnstcaseloadbyschool
caseloadbyschool.Show vbModal
Case cnstalphabetical_caseload
alphabetical_caseload.Show
Case cnstWaitingListByNeed
WaitingListByNeed.Show vbModal
Case cnstWaitingListByTimeWaite
WaitingListByTimeWaited.Sh
Case Else
Err.Raise 51001, "Reports Engine", "Unidentified Report Requested - Report Array Member " & i
End Select
End If
Exit Sub
cmdReport_Error:
FatalError
End Sub
The code which actually runs the report
Private dd As DataReport
Private bPrintingFinished As Boolean
Property Set rep(d As DataReport)
Set dd = d
End Property
Private Sub Command1_Click()
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer2_Timer()
dd.PrintReport False, rptRangeAllPages
Timer2.Interval = 0
While dd.AsyncCount > 0
DoEvents
Wend
Unload dd
Set dd = Nothing
Unload Me
I am absolutely stuck with this - I have a suspicion that if I were to get rid of the data environment altogether and use ADO recordsets then my problem would go away, but if there is an easy way to get it to work without doing all that work, I'd prefer to do it.
Thanks in advance
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Usually when things like this happen, it means that your form/report is loading before you think it is. Put a breakpoint on the form_load of the report. I bet you will find the report is loaded before you make any changes to the data. Consequently locking in the data at the time of the report.
Why the "B" grade? Was the answer not fully satisfactory?
Anthony
Anthony
dd.Refresh
dd.PrintReport False, rptRangeAllPages
Anthony