?
Solved

Reference Field on Sub-From from a Module

Posted on 2012-03-31
2
Medium Priority
?
348 Views
Last Modified: 2012-03-31
When the user enters a quanity in a field on the main form, my program calls a procedure to perform a calculation.  The calculation needs to reference another field on the subform of the main form - this is an unbound field.  This is what I came up with, but I receive an error - 2450 can't find the referenced form fsub_equipment_selected.intTrainTotal

Main Form:  frm_Opportunity_Quote
Sub Form:  fsub_Equipment_Selected
Field on Sub Form:  intTrainTotal (unbound field displays totals on subform)
Calculation:  intNoFin = intNoFin - intTrainTotal
0
Comment
Question by:Marilync1266
[X]
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 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 37791147
you use this format

Forms!frm_Opportunity_Quote!SUBFORMCONTROLNAME.intTrainTotal

open main form in design view
select/click  the outer edge of the subform control, then hit F4
select the ALL tab, the entry that you will find in the NAME property is the SUBFORMCONTROLNAME, use that in the code above

see this too as reference
Refer to Form and Subform properties and controls
http://access.mvps.org/access/forms/frm0031.htm
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 37791166
A more dynamic method (without specifically pointing to a static field in a form):
Create a public variable in the DECLARATION SECTION of a code module.

Public glbYourFieldName as string   '--- or integer, or single, whatever data type.

Now, create a fuction to retrieve this value:

Function get_glbYourFieldName() as string '--- or integer, or single, whatever data type.
get_glbYourFieldName = glbYourFieldName
End Function

Now, create a query and in the criteria section - simply enter  "=get_glbYourFieldName()

Now, in the after update event of the textbox, simply assign a value to the public variable glbYourFieldName

glbYourFieldName = "" '-- or 0 if numeric data type
if not isnull(me.txtYourTextBox) then
       glbYourFieldName = me.txtYourText Box
end if

Now, you can run that query FROM ANYWHERE and you will get your expected results.
You can also use this same query from ANY FORM simply by assigning a value to the public variable.

It's a little work (not much) but you can design whole systems around this type of procedure and reuse queries over and over again.

Scott C
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

800 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