Assigning a subform to a variable using VBA

Posted on 2003-11-13
Medium Priority
Last Modified: 2012-05-04
I am trying to compare a value on the main form with the value  on a subform.   I have assigned the main form to a variable and it works fine (see below):

Dim strParent As String, strCPersonal As String
Let strParent = [Forms]![frmempinfo]![EmpNumber]

Then, I assign the subform to a variable and  I receive the error that MS Access is unable to find the form.  Make sure it is spelled correctly and that it exists.

Let strCPersonal = [Forms]![frmChildPersonal]![EmpNumber]

frmChildPersonal is what I named the subform via the main form.  The actual name of the form is frmDISPersonal.  I tried to replace that with the frmChildPersonal and I received the same error message.

Question by:prowler2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 32

Accepted Solution

jadedata earned 2000 total points
ID: 9741751
Hey prowler2!

  This variable needs to be a form collection object.  What's more important is the name of the subform control that you need to refer to.  The name of the subform sourceobject is not used.  It is subsumed by the control.

  dim f as form

  set f = me.subformname.form
  f("controlName") = "X"


Author Comment

ID: 9748132
Thank you.  I will try this.  I haven't been to this site in a while.  Did they stop the emailing of expert responses?
LVL 32

Expert Comment

ID: 9748146
The responses are not emailed,...only notification that a question has had a comment posted to it.
LVL 39

Expert Comment

ID: 10025735
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jadedata {http:#9741751}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

719 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