My new year will be happier if I can figure out why my database hangs ...
I have a report which opens in Report view, but with Screen-only buttons on it to Print, Print Preview or Close. The Print Preview button calls an on-click event procedure as follows:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdPreviewButton_Click()
- Dim strReportName As String
- strReportName = Me.Name
- DoCmd.OpenReport strReportName, acViewPreview
- End Sub
But sometimes, instead of calling the report from the Switchboard, I need to call it in VBA with some OpenArgs from the on-click event of another form. When I do, it opens in Report view OK, but when I press the PrintPreview button it switches to print preview and then hangs. By "hangs", I mean that I can scroll up and down the report by mouse or keys, but nothing else I try in the Access window will work. I can't close the report, I can't switch to another tab in Access, I can't go to the navigation pane, I can't go to the code. But I can switch to another window (i.e. another application) and back, and then it's all alive again.
Stepping through the code, when I click the PrintPreview button it executes the OnClose routine, then the OnOpen and OnLoad and gets to the End Sub in line 5 of the above code, then goes nowhere.
Another clue: If I put a MsgBox between lines 4 and 5, the message is displayed ... and the system doesn't hang. Everything works fine. But I don't want a MsgBox there. So I tried replacing it with a DoEvents, but that was no good - it still hangs.
Another clue: If in the calling VBA I call it in PrintPreview directly, that works OK also.
Anyone got any ideas?