开发者

MS Access - Open Argument between sub forms? can I pass a value? do I need to?

开发者 https://www.devze.com 2023-01-23 23:36 出处:网络
So I have a sub form that creates a record (and record it), and then another sub form opens up for data entry...however can I still use an open arg to pass the value (ProjectID) between these sub form

So I have a sub form that creates a record (and record it), and then another sub form opens up for data entry...however can I still use an open arg to pass the value (ProjectID) between these sub forms.

I know exactly h开发者_StackOverflow社区ow to do this with forms, but trying this with subforms is a little different.

docmd.openform "FormExample",,,,,,Passingvalue

but can't do it like this:

 me.MyChild.SourceObject = "SecondSubForm",,,,,,PassingValue

so yeah the above might look ridiculous to those who know the right way, but I thought that this would illustrate exactly what I am trying to do.

So how can I pass the value? Do I even need to with subforms instead of forms? or would this variable hold my value even though it was created in the first sub form?

thanks justin


I don't think there's any way to pass an OpenArg with SourceObject =

Can it work to assign the value to a control after you set the SourceObject?

Me.MyChild.SourceObject = "SecondSubForm"
Me.MyChild!SomeControl = PassingValue


Rather than using a Hidden control as an alternative you can add a public method or public property to the Child form and then call it.

Personally I prefer to use a method because typically mutating a property shouldn't have side-effects.

Here's an example.

The child form Called SomeChildForm will have this method

Public Sub SetSomeValue(ByVal somestring As String)

     Me.Text1.Text = somestring 'or probably something to do with the record source

End Sub

From the parent you do this

Dim frm As Form_SomeChildForm
Set frm = Me.SubFormControlName.Form
frm.SetSomeValue "x"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号