Ravi Yenugu
Ravi Yenugu

Reputation: 3898

Changing subform sourceobject

In access 2010 database, I have a master form FormMaster and a subform SubFrm and I also have option group with two options optionA,option B on main form

what I want to achieve is when user changes the option ,I want to bind frmOpA to subform and when user checks option B I eant to bind frmOpB to subform FormSub

I was able to get this working using the after update event of the option group using the following code

Private Sub FrameTgt_AfterUpdate()
Select Case FrameTgt.Value
Case 1
Forms("FormMaster").Form.SubFrm.SourceObject = "frmOpA"

Case 2
Forms("FormMaster").Form.SubFrm.SourceObject = "frmOpB"
End Select

End Sub

the code changes the subforms source object fine but it doesn't seem to pull the data i.e it doesn't requery

I have tried

 Case 1
    Forms("FormMaster").Form.SubFrm.SourceObject = "frmOpA"
    Me!Subfrm.Form.Requery

but it doesn't seem to refresh I have also tried to link master and child fields in vba but no use !

any ideas?

Upvotes: 1

Views: 12927

Answers (2)

Sean Hare
Sean Hare

Reputation: 31

Your SourceObject string should be prefixed by "Form." to distinquish it from other object types like "Table.", "Query.", or "Report."

Try:

Forms("FormMaster").Form.SubFrm.SourceObject = "Form.frmOpA"

and

Forms("FormMaster").Form.SubFrm.SourceObject = "Form.frmOpB"

instead. Hope this helps.

Upvotes: 2

Robert Kupper
Robert Kupper

Reputation: 18

Have you throught about creating two FormMaster one with frmOpA and the other with frmOpB? You could then use a the on click event of the option group to move between the forms.

Upvotes: 0

Related Questions