Link to home
Start Free TrialLog in
Avatar of wlwebb
wlwebbFlag for United States of America

asked on

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

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.SetFocus
    Parent.Page4.Visible = True
    Forms![frm_DataReporting]![ShiftReportingLVL].Form![AmtOut].SetFocus
    Forms![frm_DataReporting]![ShiftReportingLVL].Controls("lblMachinePulled").Visible = False
    Forms![frm_DataReporting]![ShiftReportingLVL].Controls("MachinePulled").Visible = False
    Forms![frm_DataReporting]![ShiftReportingLVL].Form.Requery
    strCriteria = "[ShiftRptgLVLCtlID] = " & lngMyShiftRptgLVLCtlID
    Forms![frm_DataReporting]![ShiftReportingLVL].Form.Filter = strCriteria
    Forms![frm_DataReporting]![ShiftReportingLVL].Form.FilterOn = True
        
    Parent.Page6.SetFocus
    Parent.Page6.Visible = True
    strCriteria2 = "[ShiftRptgLVLCtlID] = " & lngMyShiftRptgLVLCtlID
    Forms![frm_DataReporting]![ShiftEndCashCount].Form.Filter = strCriteria2
    Forms![frm_DataReporting]![ShiftEndCashCount].Form.FilterOn = True
    Forms![frm_DataReporting]![ShiftEndCashCount]![ShiftRprgEndCountDetails_Coins].Form![Amount].SetFocus
    
Application.Echo True
    
    Parent.Page2.SetFocus
    Parent.Page2.Visible = True
    Forms![frm_DataReporting]![WVLVLControlTotals].Form![txtCtlAmtIn].SetFocus

    Parent.Page1.Visible = False
    
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good stuff, Ron - I've never tried that.
Avatar of wlwebb

ASKER

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

ASKER

Irog...
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
    Parent.Page2.SetFocus
    Forms![frm_DataReporting]![WVLVLControlTotals].Form![txtCtlAmtIn].SetFocus

To this:
    Parent.Page2.SetFocus
    Forms![frm_DataReporting]![WVLVLControlTotals].Form![txtCtlAmtIn].SetFocus

Is that correct..... Other than the code in the onload event of the particular form...
That is correct.  Just be sure to remove all your code to make pages visible or invisible.
Avatar of wlwebb

ASKER

Thanks!  Like the alternative too