Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Application defined of object-defined error

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"
0
dbfromnewjersey
Asked:
dbfromnewjersey
1 Solution
 
peter57rCommented:
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.
0
 
dbfromnewjerseyAuthor Commented:
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.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now