Application defined of object-defined error

Posted on 2011-05-04
Last Modified: 2012-05-11
I'm trying to set the recordsource of a subform using code.  I've tried both methods below and they're both giving me a "Application defined of object-defined error" message.

Using a messagebox, I checked that the variable "QueryName" is properly holding the name of the applicable query.  All of my queries run fine when I test them directly, so I don't know why I'm getting the error message.  Here are the two methods I've attempted using to assign a recordsource to the subform. "QueryName" is a variable that is assigned the name of a query based on IF THEN ELSE logic.

Method 1:
If (IsNull(ANYDATA)) Then GoTo NoDataMessage
   DoCmd.OpenForm "Form1"
   Set frm = Forms("Form1")
   With frm
      .SUBFORM1.Form.RecordSource = QueryName
    End with

Method 2:
If (IsNull(ANYDATA)) Then GoTo NoDataMessage
DoCmd.OpenForm "Form1"
Forms("Form1").SUBFORM1.Form.RecordSource = "QueryName"
Question by:dbfromnewjersey
    LVL 77

    Accepted Solution

    SUBFORM1  must be the name of the subform control on the main form  (the container control that holds the subform).  It is NOT the name of the subform, although the two are often the same.

    Author Comment

    Yup. That was the problem. somewhere along the line, I renamed the subform and was trying to use the name as it was displayed in the Objects window.  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now