Open Access form to a specific page on a tab control on a different form with VBA

风流意气都作罢 提交于 2021-01-29 04:12:15

问题


I have created a help index on a tab control with 60 pages. Each page contains helpful information to the question that corresponds to the page. The questions that are being answered are on a different form from the tab control form. I have created a button next to each question so that the user can access the help form if they need background and instructions for completing each question. I am trying to write code that will open the form and go to the correct page based on the button that was clicked. So the button for question one would open the form and go to page 1. I have tried a few different things, and can't get it to recognize the page. Below is the code that I currently have in place:

DoCmd.OpenForm "frmTestingHelp"
Forms!frmTestingHelp.SetFocus
DoCmd.GotoPage (0)

The form opens, but cannot find the page and results in an error. I started without the second line, but added it to see if the issue was that it wasn't looking for the object in the right place.
Thanks in advance!


回答1:


DoCmd.GotoPage is used only with page breaks, which hardly anybody uses. See e.g. here: http://www.functionx.com/vbaccess/Lesson13.htm and scroll down to "Using the Pages of a Form".

To select the second page of the tab control TabControl on your form:

Forms!frmTestingHelp!TabControl.Pages(1).SetFocus

or preferably, if you don't want to set the focus,

Forms!frmTestingHelp!TabControl.Value = 1

assuming you haven't changed the default PageIndex values 0,1,...



来源:https://stackoverflow.com/questions/36504693/open-access-form-to-a-specific-page-on-a-tab-control-on-a-different-form-with-vb

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