Solved

Reference Field on Sub-From from a Module

Posted on 2012-03-31
2
345 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
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

830 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