Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Refreshing subform based on selection from another subform

Posted on 2011-02-24
Medium Priority
Last Modified: 2013-11-28
My form contains Mainform, Sub1, Sub2.  On load of the Main form both subforms are hidden.  On click from Listbox, Sub1 becomes visible and list the appropriate data based on selection.

Step 2.  On Click of the Managers' name then Sub 2 should become visible and the data should be all employees assigned to the selected Manager.

However, what is happening is the Sub2 is either blank or will not requery on change of Manager's names.  See my code and let me know what I am missing.

When I return to the form from Design view it seems to be working correctly - What is preventing it from opening the sub2 form correctly with the correct data on start of the form - I am getting the error until I change the view from live to design and back again.

'******** On Load of Main Form ************************
Private Sub Form_Load()
   On Error GoTo Form_Load_Error

    If Forms!Switchboard.Visible = True Then
        Forms!Switchboard.Visible = False
    End If
        Forms![frmTrainStatus].Section(0).Visible = False
        Me.sub1.Visible = False
        Me.sub2.Visible = False
        Me.lblSub2.Vertical = False
    If IsLoaded("frmTrainStatus_Sub") Then
        DoCmd.DoMenuItem acFormBar, 4, 0, , acMenuVer20
        Me.LblMgrHdr.Visible = True
        Me.LblMgrHdr.Visible = False
    End If

   On Error GoTo 0
   Exit Sub


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of VBA Document Form_frmTrainStatus"

End Sub
'**************** On Selection of Listbox*****************
Private Sub lstUnitChief_AfterUpdate()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strSQL As String
Dim strSql1 As String
Dim strSQL2 As String
Dim MyString As String

Set db = CurrentDb()

    MyString = vbNullString
    With Me.lstUnitChief
        If .ItemsSelected.Count > 0 Then
            For Each i In .ItemsSelected
                MyString = .ItemData(i) & "," & MyString
            Next i
            MyString = Left(MyString, Len(MyString) - 1)
        End If
    End With
    Forms![frmTrainStatus].Section(0).Visible = True
    Me.sub1.Visible = True
    strSQL = "Select * from qryEmpTrain_byMGRSummary Where UCBEMS IN(" & MyString & ")" & _
                "Order by MgrName"
    Set qdf = db.QueryDefs("qrytemp")
    qdf.SQL = strSQL
    Forms![frmTrainStatus]![sub1].Form.RecordSource = "qryTemp"
    If Me.LblMgrHdr.Visible = False Then
        Me.LblMgrHdr.Visible = True
    End If
   On Error GoTo 0
   Exit Sub


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cboUnitChief_AfterUpdate of VBA Document Form_frmTrainStatus"
End Sub

Private Sub Manager_Click()
   On Error GoTo Manager_Click_Error
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSql1 As String

Set db = CurrentDb()

    gBEMS = Me.ManagerID
    gORG = Me.OrgCtr
    gMgrEmail = Nz(DLookup("StableEmail", "tblEmployee", "BEMS = " & gBEMS))
    strSQL = "Select * from qryMgrTrainTotals"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    If rs.RecordCount > 0 Then
        Forms![frmTrainStatus].Section(2).Visible = True
        Forms![frmTrainStatus]![sub2].Visible = True
        Forms![frmTrainStatus]![lblSub2].Visible = True

        Call _
            MsgBox("Please make another selection, the manager you selected currently does not any employees assigned to them.  Please update the Employee Info database and return upon completion.", _
            vbCritical, "No Data Found")
    End If

   On Error GoTo 0
   Exit Sub


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Manager_Click of VBA Document Form_frmMgrTrainStatus_sub"
End Sub

Open in new window

Question by:Karen Schaefer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 40

Expert Comment

ID: 34973083
Try Forms![frmTrainStatus]![sub2].Form.Requery

Author Comment

by:Karen Schaefer
ID: 34973095
Tried it ran into the same issue when the mdb is open for the first time, until it is opened into design view then it works correctly.  That is why I am so stumped  - I have tried various versions running into the same issue.

Accepted Solution

Karen Schaefer earned 0 total points
ID: 34974283
Figured it out - changed the requery of the subform to setting the SourceObject to the name of the subform.

        Forms![frmTrainStatus].Section(2).Visible = True
        Forms![frmTrainStatus]![sub2].Visible = True
        Forms![frmTrainStatus]![lblSub2].Visible = True
        Forms![frmTrainStatus]![sub2].SourceObject = "frmEmpTrain_SumSub"

Author Closing Comment

by:Karen Schaefer
ID: 35005329
Please see previous comment

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 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