In
Amateur said:
I am using a command button to open a form in a mainform:
Me.[dummy].SourceObject = "billshelp"
I would like that the "billshelp" Form is showing the data only based
on the clientnumber from the main form where it is opening in.
Can someone help me with the coding?
So this code is executing on the main form, and "dummy" is the name of a
subform control on that form? You can establish the filtering you want
via the Link Master Fields and Link Child Fields properties of the
subform control.
If the subform is always going to be filtered by clientnumber, you would
normally set those properties at design time. In that case, setting the
subform's SourceObject property at run time defers the loading of the
subform, but doesn't do anything else.
If you're using the same [dummy] subform control to display different
subforms, and they aren't all linked by clientnumber, then you have to
assign values to the Link Master and Child Fields properties at the time
you assign the SourceObject. You might do this:
With Me![dummy]
On Error Resume Next ' temporarily ignore errors
.LinkMasterFields = "clientnumber"
.LinkChildFields = "clientnumber"
' restore original error-handler
On Error Go To YourErrorHandlerCode
.SourceObject = "billshelp"
End With
The reason for temporarily disabling error-handling is that I have found
that Access raises an error if, in the process of setting the Link
Master/Child fields properties, I momentarily have a different number of
fields listed in one of the properties from the number of fields listed
in the other property. However, by the time I'm done setting both
properties, all is well again.