0
votes

I am trying perform a RecordsetClone but I keep getting a

Invalid Qualifier

compile error.

Currently I have a form, and within it I have a subform that contains a Datasheet. I created a function to pass in the name of the form as well as name of the subform:

Public Sub testModel(nameOfForm As String, nameOfSubform As String)
    Dim myForm As Access.Form
    Dim mySubForm As Access.SubForm

    If formIsOpen(nameOfForm) = False Then
        DoCmd.OpenForm nameOfForm, acNormal
    End If

    Set myForm = Forms(nameOfForm)
    Set mySubForm = myForm.Controls(nameOfSubform )

    With Forms!myForm.name.mySubForm.name.Form.RecordsetClone
       ...
    End With

End Sub

The reason for using a variable for the form and subform is because different forms and subforms will be using this function.

The error is definitely involved with the syntax Forms!myForm.name.mySubForm .name.Form.RecordsetClone, and I'm pretty confident it is incorrect.

I've also tried:

Forms!myForm.name.mySubForm.Form.RecordsetClone

If I replaced it, directly using the name of the form and subform name, there is no issue, i.e.:

Forms!frmParentForm.frmChildSubForm.Form.RecordsetClone

I have printed out the name of myForm and mySubForm via its .name property and it appears to display the correct name for each.

Can someone point me in the right direction on how exactly I can use variable names in place of the actual names of my form and subform? What should the correct syntax be?

Thanks!

1

1 Answers

1
votes

Remove those .name things. They're not supposed to be there:

With Forms!myForm.mySubForm.Form.RecordsetClone
   ...
End With

If you're going to use that declared subform variable, it's even more simple:

With mySubForm.Form.RecordsetClone
    ...
End With