VBA code can't find Access Form

  • I have the following code occuring in my Access form titled Tests:


    Code
    Debug.Print Forms("TestsList").RecordSource


    TestList is a subform inside Tests. Whenever I try to run this code, I get the following error:


    run time error 2450:


    ms office access can't find the form "TestsList" referred to in a macro expression or visual basic code.


    can anyone help me with this? I need to be able to see/edit the recordsource of TestsList.

  • Re: VBA code can't find Access Form


    Quote from norie

    Are you doing this when the main form is open?


    If you do then you'll need to reference the subform through the main form.

    yes, the main form is open. Are you saying I'd have to do something like:


    Code
    Forms([I]main form[/I]).subform([I]subform[/I]).[I]etc[/I]

    (I know that's wrong)


    How exactly do I reference the subform through the mainform?

  • Re: VBA code can't find Access Form


    Quote from A9192Shark

    Ski 52,


    Try me.[frmSubFrmName].Form.Recordsource


    A.


    Hello,
    I have a similar problem trying to access (no pun intended) subform fields in VBA. When I tried your solution, it failed with the message "Illegal use of me keyword". The supplied explanation didn't make sense to me. Would you provide further assistance?
    Thanks in advance,
    Nik.

  • Re: VBA code can't find Access Form


    The use of the Me keyword is only valid inside a form module. If you get an error message then you are not inside the form module.


    If you are trying to reference a field in a subform from a normal module then you will need something like:

    Code
    Forms("MainFormName").[frmSubFrmName].Form.[Fieldname]


    A.

  • Re: VBA code can't find Access Form


    Quote from A9192Shark

    The use of the Me keyword is only valid inside a form module. If you get an error message then you are not inside the form module.


    If you are trying to reference a field in a subform from a normal module then you will need something like:

    Code
    Forms("MainFormName").[frmSubFrmName].Form.[Fieldname]


    A.


    Hello again,
    Thanks for everything. It worked!.
    Nik.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!