Results 1 to 6 of 6
  1. #1
    mdev is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    2

    VBA Unable to find referenced form

    Hi all,



    I'm attempting to have a dropdown on the main form of my database change the record source for a subform with the AfterUpdate function.

    I'm completely new to VBA so I may have some sort of weird syntax error but I get the following error when I try and use the dropdown:


    "Run-time error '2450':
    Microsoft Access cannot find the referenced form 'Table1Subform'"


    I'm attempting to select the Subform with the following:
    Code:
    Forms!Table1Subform.RecordSource = strNewRecord
    If this subform is embedded within the main form, do I have to reference the main form and then the subform, or should I reference the subform directly?

    If I attempt to do:
    Code:
    Forms!Form1!Table1Subform.RecordSource = strNewRecord
    then I get the following error:

    "Run-time error '438':
    Object doesn't support this property or method"

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use the BUILDER to get the paths correct.
    but usu for subforms, its:

    forms!mainForm!subformName!form.Recordsource = xxxx

  3. #3
    mdev is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    2
    Looks like this still isn't working.

    The builder is recognising the file path but VBA isn't at all.

    Click image for larger version. 

Name:	MSACCESS_2018-03-02_13-50-53.png 
Views:	19 
Size:	2.2 KB 
ID:	32834
    Click image for larger version. 

Name:	MSACCESS_2018-03-02_13-51-31.png 
Views:	19 
Size:	9.9 KB 
ID:	32835

    Interestingly when I type 'Forms!' in the builder, the autocomplete gives me both Form1 and Table1Subform. As Table1Subform is meant to be a subform of Form1, should this be showing up here?

    If I do Forms!Form1!Table1Subform then I get this error:
    Click image for larger version. 

Name:	MSACCESS_2018-03-02_13-56-37.png 
Views:	19 
Size:	9.7 KB 
ID:	32836

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    another way is:
    instead of swapping the recordset in 1 form,
    have different forms connected to different recsets, and just swap the form

    me.subform.sourceobject= "frmSubform2"

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    It should be
    Code:
    Forms!Form1.Table1Subform.Form.Recordsource
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I'm attempting to have a dropdown on the main form of my database change the record source for a subform with the AfterUpdate function.
    if the subform is on your main form then all you need is

    subformcontrolname.form.recordsource=mysqlstr

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 12-08-2017, 02:21 PM
  2. Can't find referenced field error
    By Thompyt in forum Programming
    Replies: 7
    Last Post: 09-04-2015, 09:00 AM
  3. Unable to find Form
    By excellenthelp in forum Programming
    Replies: 2
    Last Post: 06-24-2014, 05:22 PM
  4. Replies: 1
    Last Post: 03-05-2014, 07:55 AM
  5. Unable to Find Object Error
    By MHernan1 in forum Access
    Replies: 1
    Last Post: 08-15-2013, 04:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums