Invalid Reference to Object

J

Jaybird

The syntax for subform references always gets me...

I have a main form called frmInvoice. On it I have two subforms called
qryLINPLAT and ChildsbfInvoice. I would like to set the value of a text box
(txtCreditMemo) on my ChildsbfInvoice form based on the value of the sum of
text box txtLineTotal on the subform qryLINPLAT. I've tried all kinds stuff,
but this is my code currently:

MyVariable = Sum(Me.Parent.qryLINPLAT.Form.txtLineTotal)
If MyVariable < 0 Then Me.txtCreditMemo = 0
If MyVariable >= 0 Then Me.txtCreditMemo = 1

I keep getting either an invalid reference error or a 'this object does not
support this property' error.

The purpose of this code is to set the value of txtCreditMemo (on the
ChildsbfInvoice subfrom) to zero if the sum of txtLINETOTL (on the qryLINPLAT
subform) is less than zero and to set the value of txtCreditMemo to 1 if the
sum of txtLINETOTL is greater than zero.

This will indicate to accounting if the invoice is a credit memo or not.
 
K

Klatuu

There are a couple of problems here. First, the Sum only works in queries.
In VBA code, you use the DSum, but it needs to be used on a domain (query,
table, or recordset). Also, are qryLINPLAT and ChildsbfInvoice the names of
the subform controls on the main form or are they the names of the forms
being used as subforms?
The proper way is to use the name of the subform control. A subform control
has a property named Source Object. The source object is the name of the
form being used as a sub form. So be sure you use the name of the subform
control and not the name of the form being used as a subform.

The Parent reference is used in a subform to reference the main form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top