Solved

Reference Field on Sub-From from a Module

Posted on 2012-03-31
2
340 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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

16 Experts available now in Live!

Get 1:1 Help Now