How to click through Access Report using SendKeys

為{幸葍}努か 提交于 2019-12-11 11:59:29

问题


After having slogged through creating a table of contents for my access report, I have finally gotten to the point where the code works, and a table of contents is created.

As the instructions from Microsoft state, I need to manually click through the Print Preview until the last page so that the TOC is created. This works.

How can I click through the Access Report using SendKeys?

Here is my code so far... it works perfectly, except that SendKeys does nothing!

'Click through report so that TOC code is executed
Dim rptCurReport As Report
Set rptCurReport = Screen.ActiveReport

With rptCurReport
    Application.DoCmd.SelectObject acReport, "rptFundSelectionList"
    .Visible = True 'switch to false once code is ok
    'go through all pages
    For i = 1 To .Pages
        SendKeys "{PGDN}", True
    Next i

    'DoCmd.Close acReport, "rptFundSelectionList"
End With

回答1:


I have managed to finally solve this issue for myself. Here is the code. May it help some other poor soul!

'Open report containing code to create TOC with list of ISINs from above
DoCmd.OpenReport "rptFundSelectionList", acViewPreview, , strWhere
Set dict = Nothing

'Click through report so that TOC code is executed
Dim rptCurReport As Report
Set rptCurReport = Screen.ActiveReport

With rptCurReport
    Application.DoCmd.SelectObject acReport, .Name
    .Visible = True 'switch to false once code is ok
    'go through all pages
    SendKeys "{End}", True
    DoEvents
    Application.DoCmd.SelectObject acReport, .Name
    DoCmd.Close acReport, .Name, acSaveNo
End With


来源:https://stackoverflow.com/questions/31719790/how-to-click-through-access-report-using-sendkeys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!