Access - Tabbed form - Make form Hidden....

Posted on 2012-09-13
Last Modified: 2012-09-13
Good evening.

Have a tabbed form that when it opens all the tabs EXCEPT Page1 is hidden.  I want the tabs hidden until the user selects from a series of Command Buttons.  The selection will make Visible the appropriate tabs for the selected Command Button.

After it makes visible the correct tabs then I want it to hide that Page1.

However, I'm getting an error,
Run-Time error 2165
You can't hide a control that has the focus.

The problem I believe is when it gets to the bottom of the code, the last 4 lines after the Application.Echo True (Lines 44 to 48)

Though it is in fact making Page2 visible it isn't Setting the focus to the [txtCtlAmtIn] field

Thus when it hits Parent.Page1.Visible = False it is giving me that error.......

Private Sub cmdShiftEnd_Click()
    Dim cResponse As Integer, LResponse As Integer, lngMyRptgSeqID As Integer, lngMyShiftRptgLVLCtlID As Integer, strCriteria As String, strCriteria2 As String
    cResponse = MsgBox("You selected END OF SHIFT reporting.  Are you reporting Your End of Shift Information?", vbYesNo, "IS THIS YOUR END OF SHIFT REPORTING?")
        If cResponse = vbNo Then
            Exit Sub
        End If
    LResponse = MsgBox("Is this LVL Reporting for END OF DAY?", vbYesNo, "REPORTING END OF DAY?")
        Me.cboSelectedLVLRptgType.RowSource = "SELECT LVLRptgTypeID, LVLRptgType FROM LVLReportingType WHERE (((LVLRptgType)=" & "'Shift End'" & "))" & ";"
        Me.cboSelectedLVLRptgType = Me.cboSelectedLVLRptgType.ItemData(0)

 Application.Echo False
    Call NewLVLControl
    lngMyRptgSeqID = GetMyShiftSeqID()
    lngMyShiftRptgLVLCtlID = GetMyShiftRptgLVLCtlID()
    CurrentDb.Execute "INSERT INTO ShiftReportingEndCountCtl (ShiftRptgLVLCtlID, CountType) VALUES (" & lngMyShiftRptgLVLCtlID & "," & 1 & ")", dbFailOnError
    Call GenerateLVLMachineLines1(LResponse = vbYes)
    Parent.Page4.Visible = True
    Forms![frm_DataReporting]![ShiftReportingLVL].Controls("lblMachinePulled").Visible = False
    Forms![frm_DataReporting]![ShiftReportingLVL].Controls("MachinePulled").Visible = False
    strCriteria = "[ShiftRptgLVLCtlID] = " & lngMyShiftRptgLVLCtlID
    Forms![frm_DataReporting]![ShiftReportingLVL].Form.Filter = strCriteria
    Forms![frm_DataReporting]![ShiftReportingLVL].Form.FilterOn = True
    Parent.Page6.Visible = True
    strCriteria2 = "[ShiftRptgLVLCtlID] = " & lngMyShiftRptgLVLCtlID
    Forms![frm_DataReporting]![ShiftEndCashCount].Form.Filter = strCriteria2
    Forms![frm_DataReporting]![ShiftEndCashCount].Form.FilterOn = True
Application.Echo True
    Parent.Page2.Visible = True

    Parent.Page1.Visible = False
End Sub

Open in new window

Question by:wlwebb
    LVL 61

    Accepted Solution

        Parent.Page2.Visible = True

    Try switching those two lines around.

    Set focus *after* making it visible.
    LVL 29

    Assisted Solution

    Are you just trying to hide the tabs?  Rather than go to all the trouble of setting pages to invisbile, you should just set the Style property of your tab control to None.  Personally, I like to do this by code, that way when I go in to design mode I can still quickly switch to the different pages.  In your Form's OnLoad event, just add Me.NameOfTabControl.Style = 2

    Another thing I do with tabs is set the BackStyle property to transparent.  Try these out and see if it works for you.
    LVL 61

    Expert Comment

    Good stuff, Ron - I've never tried that.

    Author Comment

    That did it!!! Thanks.......  I'm not closing this yet to think about and try Irog's comment......

    Author Comment

    I'm trying to prevent the user from being able to select the tab until they've completed the form preceeding/controlling form .....

    If you think to the last couple days, this is the project where they are selecting control buttons for EndofShift or MachinePull or ClearChip.

    Based upon which one they select it opens different tabs.

    Thus In my example code above I would guess it would go
    From this:
       Parent.Page2.Visible = True

    To this:

    Is that correct..... Other than the code in the onload event of the particular form...
    LVL 29

    Expert Comment

    That is correct.  Just be sure to remove all your code to make pages visible or invisible.

    Author Closing Comment

    Thanks!  Like the alternative too

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    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.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now