Updating subform from second mainform

  • Thread starter vmon via AccessMonster.com
  • 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?
 
W

Wayne Morgan

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.
 

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