Can't change suform source

mikemaki

Registered User.
Local time
Today, 23:30
Joined
Mar 1, 2001
Messages
81
I'm pretty stumped here. Hope someone can help.

I have a master form that contains one subform control. The master form has a number of buttons that use the following code to change the subform's SourceObject:

If Me!SurveySubSection.SourceObject = "frmSurvey120" Then
'do nothing
Else
Me!SurveySubSection.SourceObject = "frmSurvey120"
End If

If Me!SurveySubSection.SourceObject = "frmSurvey115" Then
'do nothing
Else
Me!SurveySubSection.SourceObject = "frmSurvey115"
End If


etc.

This works great in 2003. But after converting to 2007, I get an empty suibform control. Any ideas why? I know the 2007 subform has new properties. Does something there need to change?
 
Hi
what is the idea behind this?

This works fine in Ms-Access 2007.
if you try this:
Code:
        If Me!subFrmSource.SourceObject = "Form2" Then
              Me!subFrmSource.SourceObject = "Form1"
          Else
              If Me!subFrmSource.SourceObject = "Form1" Then
                 Me!subFrmSource.SourceObject = "Form2"
              End If
       End If
This will change the SourceObject of subform to Form1 and vice-versa.

Did you compile your codes?
 
This application tracks our facility's responses to what used to be a survey Child Life magazine used to rank pediatric health care facilities. Each button on the main form will load a different subform containing responses to a different section of the response.

Essentially, the syntax in your code is the same as mine. The code I provided above is code from the OnClick events of two different buttons.

I just tried an experiment. I ran the mdb file (which works fine in 2003) in Access 2007, the subform came up blank. There is something different in 2007 when it comes to assigning aa SourceObject to a subform control.
 
Try refreshing the subform after changing the SourceObject
 
Make sure you are referring to the correct item when doing this.

You need to refer to the CONTROL name on the main form which houses the subform, not the subform itself.
 
Yes, I am referring to the control. And the subform control does not support the refresh action. I also tried refreshing the main form. That doesn't work either.
 
The subform does, not the control. Could you post your db?
 
Refreshing the subform does nothing

can't post the db. I'd probably get in a lot of trouble. Its got our security wrapper on it and some other organizational standards that shouldn't be made public. I just looked at another app we have that does something similar. It works. I'll have to look at the issue more myself. I'll llet you know how it turns out.
 
Two more things to try:

1. Use the full reference
Forms("Name_Of_Main_Form").Controls("Name_Of_Subform_Control").SourceObject = "Something"

2. After setting the source object, use a message box to ensure that's the source object
 
For anyone wondering-
The reason my subforms showed up blank was the parent form was bound. This confused Access - To dynamically add a bound subform to a bound form. Once I removed the RecordSource from the main form the subform worked.
 
For anyone wondering-
The reason my subforms showed up blank was the parent form was bound. This confused Access - To dynamically add a bound subform to a bound form. Once I removed the RecordSource from the main form the subform worked.

Actually, the reason it failed is because when you dynamically set the source object you ALSO need to dynamically set the Master/Child links. If you didn't do that, then that is what the problem was.
 
Thanks. I never thought of that. Currently I'm using query criteria rather than Link fields. The values are not on the parent form. They are hidden somewhere else. But it may be easier to take your advice.
 

Users who are viewing this thread

Back
Top Bottom