开发者

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

开发者 https://www.devze.com 2023-01-21 13:42 出处:网络
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 follo

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 happe开发者_如何学JAVAning?


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.


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


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号