Solved

Refreshing subform based on selection from another subform

Posted on 2011-02-24
4
369 Views
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.

Karen
'******** 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
    Else
        DoCmd.Restore
        Me.LblMgrHdr.Visible = False
    End If

   On Error GoTo 0
   Exit Sub

Form_Load_Error:

    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
    qdf.Close
    
    Forms![frmTrainStatus]![sub1].Form.RecordSource = "qryTemp"
    
    If Me.LblMgrHdr.Visible = False Then
        Me.LblMgrHdr.Visible = True
    End If
    
    Me.sub1.Requery
   On Error GoTo 0
   Exit Sub

cboUnitChief_AfterUpdate_Error:

    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
        Forms![frmTrainStatus]![sub2].Requery
  
        Me.Refresh
        DoCmd.Maximize

        
    Else
        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

Manager_Click_Error:

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

Open in new window

0
Comment
Question by:Karen Schaefer
[X]
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
4 Comments
 
LVL 40

Expert Comment

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

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.
0
 

Accepted Solution

by:
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"
0
 

Author Closing Comment

by:Karen Schaefer
ID: 35005329
Please see previous comment
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

751 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