Source Object

  • Thread starter Thread starter Little Penny
  • Start date Start date
L

Little Penny

Can I set the Properties of a subforms Source Object from a cmd button in another form that opens the
Main form of the subform.
 
Because of timing issues, it's usually best to set the SourceObject of a
subform via programming in the main form that contains the subform. Pass the
name of the SourceObject to the main form via the OpenArgs argument of
DoCmd.OpenForm action, and then use that in the form's Load event to set the
subform's SourceObject.

DoCmd.OpenForm "MainForm", OpenArgs:="SourceObjectName"


And in the opened form's Load event:

Me.SubformName.SourceObject = Me.OpenArgs
 
Ken you are the man.

Can I use more the one OpenArgs (DoCmd.OpenForm "MainForm", OpenArgs:="SourceObjectName")

I also want to set the Label of the subform and the Caption of the form as well


Thanks
 
Concatenate all the text values into one string, but put a delimiter between
them. I usually use the pipe (|) character.

Then you can parse out the OpenArgs string into the separate names in the
opened form.

Here's some sample code:

(in the calling form)
Dim strOpenArgs As String
strOpenArgs = "SourceObjectName" & "|" & "LabelText" & _
"|" & "CaptionText"
DoCmd.OpenForm "MainForm", OpenArgs:=strOpenArgs


(in the main form that is called)
Dim varOpenArgs As Variant
varOpenArgs = Split(Me.OpenArgs, "|")
' varOpenArgs(0) contains the "SourceObjectName"
' varOpenArgs(1) contains the "LabelText"
' varOpenArgs(2) contains the "CaptionText"
 
Back
Top