X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Problem With Frm = Vstrings(sequence) To Run A Procedure.    
post Nov 1 2016, 04:15 AM

Posts: 15
Joined: 18-August 16

Dear people,

I hope that you can help me with my problem about "frm". See below my procedure. It doesn't happen with my procedure. But if "Vstrings(Sequence)" of "frm" is replaced with "Forms![frm_D_MODI]![fsub_D_MODI_FN_Materials]![fsub_D_MODI_FN_PCR_1].Form", then the procedure is running wel. I don't understand why only "Vstrings(Sequence)" doesn't work? confused.gif My aim is if I change the rowsource of combobox, this change also happens in a combobox with same name at the other forms. big_grin.gif

With kindly regards,


Private Sub Form_Current()
    On Error Resume Next
    'AC = ActiveControl     RS = RowSource      PIN = Personal Indentification Number       FN = Follow Number      CBO = ComboBox
    Dim frm As Form, ACName, CBORSPIN As String, ctl As Control, Sequence As Long, Vstrings As Variant
        Vstrings = Array("Forms![frm_D_MODI]![fsub_D_MODI_FN_Materials]![fsub_D_MODI_FN_PCR_1].Form", _
                         "Forms![frm_D_MODI_AL_WL]![fsub_D_MODI_AL_WL_Patients].Form", _
        For Each ctl In Me.Controls
            With ctl
                ACName = .Name
                CBORSPIN = Me.Controls(ACName).RowSource
                    If .Name = acComboBox And InStr(.Name, "PCR_Result") Or InStr(.Name, "PCR_Transcript") Then
                        For Sequence = LBound(Vstrings) To UBound(Vstrings)
                            Set frm = Vstrings(Sequence)
                            With frm
                                If CBORSPIN <> .Controls(ACName).RowSource Then
                                    .Controls(ACName).RowSource = CBORSPIN
                                End If
                            End With
                    End If
            End With
End Sub
Go to the top of the page
post Nov 1 2016, 06:21 AM

UtterAccess VIP
Posts: 7,061
Joined: 30-June 11

I'd think you'd need to create either a multi-dimensional array, or a second array. 1 for the form and one for the subform and index the data to match up. The you could do something like:
Set frm = Forms!(Vstrings(Sequence))!(VstringsSubForm(Sequence)).Form

So I'm thinking in you scenario, something like:
Function f()
    Dim frm                   As Access.Form
    Dim ctl                   As Access.Control
    Dim Sequence              As Long
    Dim Vstrings              As Variant

    VstringsFrm1 = Array("frm_D_MODI", _
                         "frm_D_MODI_AL_WL", _
    VstringsFrm2 = Array("fsub_D_MODI_FN_Materials", _
                         "fsub_D_MODI_AL_WL_Patients", _
    VstringsFrm3 = Array("fsub_D_MODI_FN_PCR_1", _
                         "", _

    Vstrings = Array("Forms!Form1.Form")
    For Sequence = 0 To 2
        If VstringsFrm3(Sequence) <> "" Then
            Set frm = Forms(VstringsFrm1(Sequence)).Controls(VstringsFrm2(Sequence)).Form.Controls(VstringsFrm3(Sequence)).Form
            Set frm = Forms(VstringsFrm1(Sequence)).Controls(VstringsFrm2(Sequence)).Form
        End If
        Debug.Print frm.Name
    Next Sequence

    Set frm = Nothing
End Function
Go to the top of the page
post Nov 2 2016, 03:25 AM

Posts: 15
Joined: 18-August 16

Dear DanielPineault,

Thank you for your help and advice. I've change my procedure and it's working now. thanks.gif

P.S. What's difference between "Form" and "Access.Form" (see Dim frm As Access.Form)?
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    18th January 2020 - 03:35 PM