Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use the OpenForm method to open a specific page of the form? 1

Status
Not open for further replies.

nowickil

Programmer
Dec 11, 2002
31
US
Hello,

I am modifying a database that I inherited from someone else. It has a form that has 6 pages in its pages collection. Most of the time, we simply need to open the form to show the first page of the form (with tabs to click on for the rest of the pages in the collection). Now, I have the need to open the form directly to one of the other tabbed pages in the page collection. How do I go about doing this? Do I set up the form name to somehow reference the proper page index, and then use the OpenForm method? Are TabCtl0 and/or SetFocus involved in what I'm trying to do?

Thanks in advance for your help,
 
To set the form to open to a particular page do this:
Set this on your form's "On Open" event:
- Change "Page175" to the name of the tab page

Me!Page175.SetFocus

jbehrne
 
Setting the On Open event on the form certainly does open the form to the page I want. However, it always opens it to that page. Perhaps I wasn't clear.

I don't want the form to always open to the same page. Most of the time, it should open to page "Customer", but there is one circumstance where I want to code this so that it will open to the "Contract" page. In a VB module, I will be setting up an OpenForm method to open the form. How do I specify the form page that I want using VB? Is this the wrong forum for this post?

thanks,
 
Hi,

Sorry, I got a little confused... In order for you to open the form and go to a specific page you will either need some input from your user or post the code that is driving the form's opening. Then based on that set the code based on a simple If... Then... statement or a case statement.

In order to do that I need to know how the form is being opened now. Is it from a button on a form/switchboard or is there some underlying event that opens the form (I.E. The form is opened if the user selects a new record)

Please post more info!

jbehrne
 
Hi,

The form will open when the user selects (double clicks) an item in a list of customers with contracts that are about to expire. That is the point where I want to open up the Customer form to the customer's contract page.

Private Sub lstContractList_DblClick(Cancel As Integer)

Dim stFormName As String
Dim stLinkCriteria As String

stFormName = "frmCustomer"
stLinkCriteria = "[CustID]=" & lstContractList.Value

DoCmd.Close
DoCmd.OpenForm stFormName, , , stLinkCriteria

End Sub

As you can see, I'm passing the customer id, and pull just the record for that customer. How can I also pass the specification for which page of the form to display?

Thanks for all of your help,
 
Okay,

This should open the form to the page you want it to:

Private Sub lstContractList_DblClick(Cancel As Integer)

Dim stFormName As String
Dim stLinkCriteria As String

stFormName = "frmCustomer"
stLinkCriteria = "[CustID]=" & lstContractList.Value

DoCmd.OpenForm stFormName, , , stLinkCriteria

'this is were you will set your page name to open to the
'specific page that you want the form to open to
Forms!frmCustomer.PageName.SetFocus
DoCmd.Close "Your Original Form"
End Sub

- Note: I have changed the DoCmd.Close, if you want to close the first form close it after have opened the other form and set its focus.

Hope this helps,

jbehrne
 
Excellent, thank you. It worked. I had tried a variation on that before, but forgot the Forms! reference. Have a great day,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top