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

Automation Error on MsAccess reports

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

When I run the following code to modify design of a report I get an automation error if I run it more than once (first time works!!!)

Dim Obj As Object
Dim Rep As Report
Set Obj = CreateObject("access.application")
Obj.Visible = False
Obj.OpenCurrentDatabase DBPath & "InterfaceRapports.mdb"
Obj.DoCmd.OpenReport QueryName, acViewDesign
Set Rep = Obj.Reports(QueryName)
'Rep!Start.ControlSource = "=Format(DateAdd('h', " & DST & ", [gmt_strt]), 'hh:nn')"
'Rep!lblTitle.Caption = ReportTitle
Obj.DoCmd.Close acReport, QueryName, acSaveYes
Obj.DoCmd.OpenReport QueryName, acViewNormal
Obj.CloseCurrentDatabase
Obj.Quit
Set Obj = Nothing
Set Rep = Nothing

In debug mode, the problem for my automation error seems to be for
Set Rep = Reports(queryname)
The first time I run it in debug mode, when I move my mouse cursor over "Reports" is gives me the following:
Object variable or with block variable not set
But it does accept anyway and continues on
The second time I run the code, instead of the above message I get Automation Error!
 
Where are you getting the value of 'QueryName'? Is it a string? I don't see it anywhere in your code. I ran your code successfully using a test report called 'rptTest' instead of QueryName. I also hardcoded the path because I could not get it to work with DBPath. I ran it 4 or 5 times with no errors.

Kelly
 
Hail Kelly,

Queryname comes from a combobox the user selects. DBpath works well from my side (it retrieves the path from a text file in the same folder as the app's)
For some reason, when I transform the project in a executable, it does not crash??? I'm running VB5 on WinNT server, maybe that is the problem?

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top