Changing Subform's RecordSource Errors

Bill Bisco

Custom User Title
Local time
Today, 09:30
Joined
Mar 27, 2009
Messages
92
In the following code I am attempting to change the RecordSource of the Subform. I'm getting an error message at the line

Code:
        Me!frmProcessSelectLSSubform.RecordSource = strFormName

The Current Name of the Child is frmProcessSelectLSSubform and the Current Source Object is called frmProcessSelectLSSubform

If anyone could show me how to fix this error, it would be appreciated. Below is my whole code:

Code:
Private Sub cmdState_Click()

Dim cap As String
cap = Me.cmdState.Caption

Dim strFormName As String
Dim strFilter As String

Select Case cap

    Case "View Current"
        With Me
            .cmdState.Caption = "View Proposed"
        End With

        strFormName = "frmProcessSelectCurrentLSSubform"
    
        If IsFormLoaded(strFormName) Then
            DoCmd.Close acForm, strFormName, acSaveYes
        End If
    
        DoCmd.OpenForm strFormName, acNormal, strFilter, , , acHidden

        Me!frmProcessSelectLSSubform.RecordSource = strFormName
 
        DoCmd.Close acForm, strFormName, acSaveYes
 
    Case "View Proposed"
        With Me
            .cmdState.Caption = "View Current"
        End With
        
        strFormName = "frmProcessSelectLSSubform"
        
        If IsFormLoaded(strFormName) Then
            DoCmd.Close acForm, strFormName, acSaveYes
        End If
    
        DoCmd.OpenForm strFormName, acNormal, strFilter, , , acHidden

        Me!frmProcessSelectLSSubform.RecordSource = strFormName
 
        DoCmd.Close acForm, strFormName, acSaveYes
        
End Select
    
    Me.Refresh
    
End Sub
Sincerely,
Bill
 
Thanks for the reply Bob.

When I add the .Form, I get a different Error, it now says

The record source 'frmProcessSelectCurrentLSSubform' specified on this form or report does not exist

I have tried changing the Name of the child, but I have gotten the same error.
 
I have found a solution to this problem by browsing another forum.

The format to use to change the RecordSource of the Subform is:

Code:
Forms!MainFormName![SubformContainerName].SourceObject = "frmDifferentForm"
For my database the proper code was

Code:
Forms!frmProcessSelectLSRS![frmProcessSelectLSSubform].SourceObject = strFormName
Peace,
Bill
 
Last edited:

Users who are viewing this thread

Back
Top Bottom