Problems setting the sourceobject of a subform...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I have a mainform on which is a subform. I use the .sourceobject property to
change the sourceobject of the subform to display various forms within the
subfoirm container...

If I hard code the form name as shown below the statement works no problem.
However, I want to use a database field name (so I can make a generic
function to load the correct form) and I get the following error...

"The setting you entered isn't valid for this property."

Here is the code that works...

Forms![frmPricing].[frmPricingDetail].SourceObject = "frmFormName"

Here is the code that fails...

' RS!FormToLoad comes from a table containing the form name...
strFormToLoad = & """" & RS!FormToLoad & """"

Forms![frmPricing].[frmPricingDetail].SourceObject = strFormToLoad


Can anyone help me with this ?

Thanks,

Brad
 
Brad Pears said:
I have a mainform on which is a subform. I use the .sourceobject
property to change the sourceobject of the subform to display various
forms within the subfoirm container...

If I hard code the form name as shown below the statement works no
problem. However, I want to use a database field name (so I can make
a generic function to load the correct form) and I get the following
error...

"The setting you entered isn't valid for this property."

Here is the code that works...

Forms![frmPricing].[frmPricingDetail].SourceObject = "frmFormName"

Here is the code that fails...

' RS!FormToLoad comes from a table containing the form name...
strFormToLoad = & """" & RS!FormToLoad & """"

Forms![frmPricing].[frmPricingDetail].SourceObject = strFormToLoad


Can anyone help me with this ?

It seems to me that you don't need to stick any extra quote around
RS!FormToLoad, since you're just assigning a text value to a text
property. Try this:

Forms![frmPricing].[frmPricingDetail].SourceObject = RS!FormToLoad
 
did you try this?

Forms![frmPricing].[frmPricingDetail].SourceObject =
nz(RS("FormToLoad"),"Blank")

nz is used to capture nulls and then it will set the Blank form as subform

- Raoul
 
Back
Top