Problems setting the sourceobject of a subform...

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
 
D

Dirk Goldgar

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top