Access and CR - Invalid Reference Error??????

B

Bob

Hello All,

I've been stuck on this one for far too long. I need help.

I wrote an Access application that calls Crystal Reports for all the various reports. When I run the report (any one of them) everything works as
expected. When I try to run a second time (whether it's the same report or not) it comes up with an error:

Run-time error '-2147483638 (8000000a)'
You entered an expression that has an invalid reference to the property |.

I can't track the error down. It appears to have something to do with the window border color, but not sure. Am I not initializing something the
second time around or did I not close and release objects properly, etc????

My code is shown below:

Would really like to put this project to bed,

Bob.


Access 2003, Crystal Reports v10
================================================
Option Compare Database
Public crxApplication As New CRAXDDRT.Application
Public crxReport As CRAXDDRT.Report
Public crxExportOptions As CRAXDDRT.ExportOptions
Dim crxParamDefs As CRAXDDRT.ParameterFieldDefinitions
Dim crxParamDef As CRAXDDRT.ParameterFieldDefinition

Public TheReportPath As String
Public TheReportFile As String

Private Sub Form_Load()
TheReportPath = "C:\Test\"
End Sub

Private Sub btnRpt016_Click()
TheReportFile = TheReportPath & "R105016.rpt"
ReportOnMir ("")
End Sub

Private Sub ReportOnMir(rpt As String)
Me!CRViewer1.Visible = True
Me!CRViewer1.top = 700
Me!CRViewer1.Left = 50
Me!CRViewer1.Height = 7500
Me!CRViewer1.Width = 12900
Me!CRViewer1.DisplayGroupTree = False

Dim crxApplication As New CRAXDDRT.Application
Set crxReport = crxApplication.OpenReport(TheReportFile)
Set crxParamDefs = crxReport.ParameterFields
crxReport.RecordSelectionFormula = "{MirMaster.MIRCtl} = " & CStr(Me![MIRCtl])
For Each crxParamDef In crxParamDefs
With crxParamDef
Select Case .ParameterFieldName
Case "MIRNumberParam"
.SetCurrentValue (Me![MIRCtl])
Case "MIRDateParam"
.SetCurrentValue CDate(Me![MIRDateInit])
End Select
End With
Next
Me!CRViewer1.ReportSource = crxReport 'Set ReportSource to the report object
Me!CRViewer1.ViewReport 'View the report
Set crxReport = Nothing
End Sub
 
S

Steve Sanford

Hi Bob,

Since the report runs correctly the first time and errors the second time,
and you get an error about an invalid reference, I would look at the last
line of the sub "ReportOnMir".

My reasoning:

~ You created a module global variable "Public crxReport As CRAXDDRT.Report"
~ The last line of the sub,

"Set crxReport = Nothing"

destroys the pointer to the variable.


You might try changing the last couple lines of code to:

Private Sub ReportOnMir(rpt As String)
<snip>
<snip>
Me!CRViewer1.ViewReport 'View the report
crxReport.Close
' Set crxReport = Nothing
End Sub


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Bob said:
Hello All,

I've been stuck on this one for far too long. I need help.

I wrote an Access application that calls Crystal Reports for all the various reports. When I run the report (any one of them) everything works as
expected. When I try to run a second time (whether it's the same report or not) it comes up with an error:

Run-time error '-2147483638 (8000000a)'
You entered an expression that has an invalid reference to the property |.

I can't track the error down. It appears to have something to do with the window border color, but not sure. Am I not initializing something the
second time around or did I not close and release objects properly, etc????

My code is shown below:

Would really like to put this project to bed,

Bob.


Access 2003, Crystal Reports v10
================================================
Option Compare Database
Public crxApplication As New CRAXDDRT.Application
Public crxReport As CRAXDDRT.Report
Public crxExportOptions As CRAXDDRT.ExportOptions
Dim crxParamDefs As CRAXDDRT.ParameterFieldDefinitions
Dim crxParamDef As CRAXDDRT.ParameterFieldDefinition

Public TheReportPath As String
Public TheReportFile As String

Private Sub Form_Load()
TheReportPath = "C:\Test\"
End Sub

Private Sub btnRpt016_Click()
TheReportFile = TheReportPath & "R105016.rpt"
ReportOnMir ("")
End Sub

Private Sub ReportOnMir(rpt As String)
Me!CRViewer1.Visible = True
Me!CRViewer1.top = 700
Me!CRViewer1.Left = 50
Me!CRViewer1.Height = 7500
Me!CRViewer1.Width = 12900
Me!CRViewer1.DisplayGroupTree = False

Dim crxApplication As New CRAXDDRT.Application
Set crxReport = crxApplication.OpenReport(TheReportFile)
Set crxParamDefs = crxReport.ParameterFields
crxReport.RecordSelectionFormula = "{MirMaster.MIRCtl} = " & CStr(Me![MIRCtl])
For Each crxParamDef In crxParamDefs
With crxParamDef
Select Case .ParameterFieldName
Case "MIRNumberParam"
.SetCurrentValue (Me![MIRCtl])
Case "MIRDateParam"
.SetCurrentValue CDate(Me![MIRDateInit])
End Select
End With
Next
Me!CRViewer1.ReportSource = crxReport 'Set ReportSource to the report object
Me!CRViewer1.ViewReport 'View the report
Set crxReport = Nothing
End Sub
 
B

Bob

Steve,

Did as you suggested, but came up with a different error:

Run Time Error: '438'
Object doesn't support this property or method.

Reading into your response a bit I wonder if I made all my global variables local to the subroutine and did not try to close or set anything, would
that work?

If you have any other ideas please followup.

Thanks,

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top