Assigning a subform to a variable using VBA

Posted on 2003-11-13
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
  • 2
LVL 32

Accepted Solution

jadedata earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

910 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

23 Experts available now in Live!

Get 1:1 Help Now