webworm
webworm

Reputation: 11019

Access - Report opens and then is hidden when opening form is closed

I am using Access 2003 and I have a form that collects some filtering criteria for the report. Once the criteria is entered the user clicks and "OK" button and the report is launched using the following VBA.

DoCmd.OpenReport "ReportName", acViewPreview

After the report is opened I issue the following command to close the form that collected the filtering criteria ...

Me.Close

The form closes however the report, which I wanted to stay open in the foreground, is hidden. Any idea why this is happening?

Upvotes: 0

Views: 11907

Answers (4)

Rspaeth
Rspaeth

Reputation: 1

I struggled with this for a couple days. It seems you need to close the current window and then open the report in Print Preview.

I have a button on a pivotchart embedded in a Report. (Access2010) When i tried to just print the report- any filtering on the pivot chart didn't get carried over to the "DoCmd.Printout" command.

It was suggested I use open the print preview window, but it never received focus. I had to click off screen then back toe the print preview window. The code below seems to correct this.

Private Sub Command1_Click()
DoCmd.Save
DoCmd.Close
DoCmd.OpenReport "R-MyReport", acViewPreview

Upvotes: 0

Paco Villacastin
Paco Villacastin

Reputation: 11

Try setting the Report property Modal to Yes (in Other Properties).

Upvotes: 1

David-W-Fenton
David-W-Fenton

Reputation: 23067

When all else fails with forms and reports coming to the front at the desired time, you can do it explicitly with DoCmd.SelectObject:

  DoCmd.OpenReport "rptMyReport", acViewPreview
  DoCmd.SelectObject acReport, "rptMyReport"
  DoCmd.Close acForm, Me.Name

If that doesn't work, there's something else involved, like forms or reports opened with the acDialog switch, or with forms/reports having the Modal or Popup properties set to True.

Or, there might be a timer running somewhere that's causing something to happen that's grabbing focus.

Upvotes: 1

Fink
Fink

Reputation: 3436

Does closing the form, then opening the report work? I'm guessing it has to do with the focus being shifted back and forth between the objects.

EDIT

Your code should look something like this:

Private Sub Command0_Click()

    'your code here

    DoCmd.Close acForm, Me.Name

    DoCmd.OpenReport "Report1", acViewPreview

End Sub

Also, there is no native close function as others have pointed out.

Upvotes: 0

Related Questions