Reputation: 3337
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
Upvotes: 1
Views: 385
Reputation: 3337
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
Upvotes: 1