set active tab on tabbed control

Posted on 2005-03-18
Medium Priority
Last Modified: 2008-03-06
I have a main form with tabbed control on it. The following Open event for the main form is making the second tab on the form the active tab:

Private Sub Form_Open(Cancel As Integer)

' The underlying recordset for the main form uses lngIndOrg as the primary key
' with lngInd (Individual) as one foreign key and lngOrg (Organization) as the second.
' The subforms on pgInd (the first tab) are linked on lngInd. The subforms on pgOrg
' (the second tab) are linked on lngOrg.

    Me.OrderBy = "lngIndOrgID DESC"
    Me.OrderByOn = True

End Sub

I'm not getting why the OrderBy is making the second tab the active tab. I'd like to make pgInd the active tab without changing the focus from a control on the main form. How would I go about it?

Question by:eliwil
  • 2
LVL 58

Expert Comment

ID: 13573151
I don't have the answer. Your code alone should not change the active tab on the tab control...

However, there are two workarounds:

1) save the form once it is open and then remove the Form_Open event. The OrderBy and OrderByOn are saved as form properties and will be active the next time you open it.

2) add the sort order in the form's query. Go to RecordSource and click the builder button [...]. If you are actually creating the query from the table, drag the start to the query grid (select all fields) and then drag the field lngIndOrdID, remove the "show" checkbox and select "sort: descending".

In both cases, the Form_Open event is no longer needed and this should work around your problem.

Hope this helps!

Author Comment

ID: 13573369
I went ahead and changed the record source to a query with the desired sort order but am curious about the first work around above. Can you elaborate more on how to implement? Where do I save the form once it is open and how do I then remove the Form_Open event?

Thanks for the help!
LVL 58

Accepted Solution

harfang earned 2000 total points
ID: 13573478
That is easy:

In design view of the form, the third property is called "Order By". You can check which sort order has been last saved with the form right there. To save the form while open, simply use "File / Save" or the [Save] button on the menu bar. This is actually a misfeature of the Access interface, as most users believe they are saving the -record- and not the -form-. Saving the record is found under "Records / Save record" and the change I have made most for users is to replace the default save button by a "save record" button... No point in saving the form each time you want to save the record, is there?

To remove the Form_Open event, simply delete the entire procedure in the module window:
* find the "On Open" property of the form (in design view)
* press the builder button next to "[Event Procedure]" (the [...])
* double-click in the margin (this selects the procedure)
* press Del.

If there is nothing else in the module, switch back to the form and find the very last property "Has Module" and set it to "No". This will delete the entire module from the form.

Note: make backups first, of course, I don't want you to loose any significant work! :)

Good Luck

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question