Referencing the main form

skwilliams

Registered User.
Local time
, 20:13
Joined
Jan 18, 2002
Messages
516
My mind has gone blank today. I have a procedure to run for a subform field which needs to multiply a total from a field on the subform and a field on the main form. Can someone provide me with the correct syntax for this code.

Thanks.
 
Just remember to reference the name of the mainform prior to the field name that you wish to perform the calculation on!
 
Here's the line of code I'm using on the event procedure.

Total = Price * Form!frmMQuotes!Text33 / 1000

The form "frmMQuotes" is the main form and the procedure is running from the subform.

I receive a run-time error 2465 (Access cannot find the field frmMQuotes referred to in your expression.

If changed to:
Total = Price * frmMQuotes!Text33 / 1000
I receive the error (Object required).

What am I missing?
 
You wrote
<<
Total = Price * Form!frmMQuotes!Text33 / 1000
>>

Try this:
Total = Price * Me.Parent![Text33] / 1000

"Me" is the form in which this code runs.
"Parent" is a property of the subform.

RichM
 
i have a related question maybe someone could help out on...this is my first time working with subforms...i have one main form containing two subforms on it....

the main form is called: frmmainfrm
one subform is called: frmreleasesubform

I am using Access '97 and do not know the syntax to refer to objects both from the subform to the main form as well as vice versa....i used coding from the access help files and am not sure if I am doing it right....any help would be great....

an example of something i am trying to do is check for null values when using the "Add Record" button contained on the subform....

If IsNull(Forms!frmreleasesubform.[txtbuilddate].Value) Then
MsgBox "Please Enter Build Date!", vbOKOnly, "No Build Date"
Exit Sub
End If
 
you wrote
<<
the main form is called: frmmainfrm
one subform is called: frmreleasesubform
>>

Access DOES NOT CARE what you name a subform.

Access DOES CARE what you name the **control** that contains the subform.

To refer to controls on a subform the basic syntax is:
Forms![MainFormName]![NameOfSubFormCONTROL].Form![NameOfControlInSubform]

In this example, the actual name of the subform is not used.

HTH,
RichM
 

Users who are viewing this thread

Back
Top Bottom