Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Posts
    2

    Question Unanswered: How to refer to subform control in VB code using parameters?

    Hi,

    I wrote a procedure that open a pop up form to capture information when you click on a field in a main form. When the info is captured I need to update that field if I click OK on the pop Up Form. I am able to do it when the field is on the parent form. But I don't know how to refer to that field when it's in a subform.

    Here is what I did with success if the field is on the parent form.

    The two main parameters of the procedure are the initial form name (fname as String) and the field name to updated (fieldname as String).

    So i did

    Sub ProcedureTriggeredWhenIclickOnField (fname as String, fieldname as String, ...)
    Dim frm As Form
    Set frm = Forms(fname)
    ....
    EndSub


    From my pop up form, to refer to the field to update when I click OK, I do this to update that field

    Private Sub CloseForm_Click()
    ...
    frm(fieldname).Value = InfoCapturedOnPopUpForm
    ...
    EndSub

    I don't know how to do it when the field to update is in a subform.

    I tried as fname:
    SubFormName
    ParentFormName!SubFormName
    ParentFormName!SubFormName.form
    Forms!ParentFormName!SubFormName.form

    Nothing works!!!

    Thanks for your help

    Francois

  2. #2
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    So you have a . . .

    ParentForm
    SubFormOnParentForm
    PopUpForm

    When the click a button on the ParentForm (or maybe, on the SubFormOnParentForm) you go to a subroutine which opens the PopUpForm.

    Then, on close of the PopUpForm, you want to update a field on the SubFormOnParent Form.

    I can think of several ways to do this, but the way I prefer is this . . .

    Create three invisible fields on your PopUpForm (make them visible while you are developing and debugging). One field will be the [UpdateThisParentForm] field. Another field will be the [UpdateThisSubFormOnParentForm]. And the last field will be the [UpdateThisField].

    When you open this PopUpForm, update these fields with the text values of the appropriate names. IMPORTANT--the name of the subform field should be the name of the subform control on the main form, not the form name of the subform!

    Then, on the close of the PopUpForm simply use the following to update the field on the subform.

    forms([UpdateThisParentForm])([UpdateThisSubFormOnParentForm]).form([UpdateThisField])

  3. #3
    Join Date
    Mar 2002
    Posts
    2

    Smile Thanks

    Thank you very much,

    It's working now.

    This is the part I needed:
    forms([UpdateThisParentForm])([UpdateThisSubFormOnParentForm]).form([UpdateThisField])

    I was not able to find the exact syntax.

    Thanks again

    Francois

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •