Updating subform from second mainform

  • Thread starter Thread starter vmon via AccessMonster.com
  • Start date Start date
V

vmon via AccessMonster.com

I need to update a field on a mainform1!subform from a mainform2. I want
it to be generic so I can call mainform2 from several different forms and
set a textbox equal to a value on mainform2. This is what i am trying and
I get type mismatch.

I set both of these from the calling form. txtMainForm, txtSubForm


Dim myform As String

myform = Me.txtSubForm & "!" & Me.txtObject

Forms(txtMainForm!txtSubForm)!ID_UNIT = Me.ItemId

Any ideas?
 
Forms(txtMainForm!txtSubForm)!ID_UNIT = Me.ItemId

The part inside the parenthesis needs to be a string. A string variable
would work, but it appears that what you're trying to do is take the value
from two textboxes. The value needs to be the name of a form, so there
wouldn't be a ! in it. The form you would call would be the main form, the
subform isn't open as a member of the Forms collection, it is opened as an
object of the main form. The syntax to refer to a control on the subform
would be:

Forms("NameOfMainForm")!ctlNameOfSubformControl.Form!ctlNameOfControlOnSubform

In your example, you may be able to use:

Forms(Me.txtMainForm)!Controls(Me.txtSubForm).Form!ID_UNIT

However, txtSubForm will need to be the name of the subform control on the
main form, not the name of the subform itself. They may or may not have the
same name. The subform control is a container control on the main form. This
control holds the subform.
 
Back
Top