Link to home
Start Free TrialLog in
Avatar of Marilync1266
Marilync1266

asked on

Reference Field on Sub-From from a Module

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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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