How to click through Access Report using SendKeys

2019-08-04 08:37发布

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条回答
Ridiculous、
2楼-- · 2019-08-04 09:14

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
查看更多
登录 后发表回答