access crash

evilman

Registered User.
Local time
Today, 15:11
Joined
Apr 25, 2003
Messages
31
well that's not new. Access crashes a lot. But I can't seem to find a workaround this time.
First of all, here's my situation. I have a big 11x17" report with 7 subreports that are identical in it. The only difference between the 7 subreports are some of the properties.
Now, when I want to modify one of those subreports, I have to apply the modification to every one of them, so it takes time.
Instead, I wrote a subroutine to copy every subreport, and change their properties accordingly.
I am capable of modifying most of the properties, but the only one that cannot be modified without a crash is RecordSource.

For some reason, I get a crash, or some weird error, depending on the situation.

here's my code: (the code is in a module, not in the report)
Public Function crash()
DoCmd.OpenReport "Report1", acViewDesign 'opens the report in design mode..
Report_Report1.RecordSource = "sometable"
End Function

as soon as it hits the second line, it crashes, but this time with a Visual C++ Runtime error dialog, which is weird... the error seems to have escaped access' unhandled exception catcher.

Consider the following code:
Public Function nocrash()
Dim ReportArray As Variant
Dim ReportArrayStr As Variant
Dim i As Long

ReportArray = Array(Report_Report1)
ReportArrayStr = Array("Report1")

For i = LBound(ReportArray) To UBound(ReportArray)
DoCmd.OpenReport ReportArrayStr(i), acViewDesign 'opens the report in design mode..

ReportArray(i).RecordSource = "sometable"
Next i
End Function

Access will not crash. It will give me a strange error:
"The Method 'RecordSource' of the object '_Report_Report1' has failed".
What's strange about this message is that the "Debug" button is disabled.
All that I can do is stop the execution.

Is there any workaround for this?

Oh yes, and one last thing. Some methods in access require the string name of a report, like:
DoCmd.Close acReport, "MyReport"
while some others need a reference to the report:
Report_MyReport.Caption = "Some Caption"

Would there be a way to get a reference to a report with its name, or get its name from its reference?
 
Okay, You wont have to read my entire post, I seem to have found a workaround... It gives me an error but it modifies the property!! oh well:

Public Function nocrash()
Dim ReportArray As Variant
Dim ReportArrayStr As Variant
Dim i As Long
Dim orpt as Object

ReportArray = Array(Report_Report1)
ReportArrayStr = Array("Report1")

For i = LBound(ReportArray) To UBound(ReportArray)
Set orpt = ReportArray(i)
DoCmd.OpenReport ReportArrayStr(i), acViewDesign 'opens the report in design mode..

On Error Resume Next
orpt.RecordSource = "sometable"
On Error Goto 0
Next i
End Function

access will give me an error, but the property will be modified...

But I still have an additional question:

Some methods in access require the string name of a report, like:
DoCmd.Close acReport, "MyReport"
while some others need a reference to the report:
Report_MyReport.Caption = "Some Caption"

Would there be a way to get a reference to a report with its string name, or get its string name from its reference?
 
to get a reference to a report with its string name
Forms!formstringname
or
Forms("formstringname")

get its string name from its reference
use the name property like:
Me.Name
Reports("reportname").Name
 

Users who are viewing this thread

Back
Top Bottom