Refer to Sub-form (Controls) from Main Form , Possible ?

D

Dave Elliott

I cant seem to make my code refer to the sub-from to check for Nulls. The
main form name is FPayments and the sub-form's name is FPaymentSub.
Alternatively can I put a control ('s) on main form that refers to sub-from
and use it to check for nulls on the sub-form ?
i.e. The controls on the sub-from that I want to check are Payment
(This is where a payment is made) You should not be able to pay this Invoice
without a payment being made of course, hence the If IsNull statement.
Also on the sub-form is a control named PayType which is used for
payment type, i.e. Check, Cash, etc...
If this payment type is Check then I want the next control which is named
CheckNo to have a value in it, like check number.
IF all these conditions are met, then the Invoice can be saved.

I was thinking of adding TextBoxes to the main form which are bound to the
sub-form (Payment,PayType,CheckNo) and then use them for the If IsNull
condition. The Text Box to mark as paid these Invoices is on the main form,
not the sub-form.


Any Suggestions ? Thanks, Dave
P.S. Tried using this Code, but with no luck on the OnClick Event TexBox on
the main form.

If IsNull(Payment) Then
MsgBox "Need PaymentType"
Cancel = True
ElseIf PayType = "Check" And IsNull(CheckNo) Then
MsgBox "Need check number"
Cancel = True
End If
 
L

Larry Tompkins

Hi Dave,
If you refer to a sub-form control from the main form you
must use the following syntax.
Forms!MainFormName!SubFormName.Form!ControlName

So your code:
If IsNull(Forms!FPayments!FPaymentSub.Form!Payment) Then
MsgBox "Need PaymentType"
Cancel = True
ElseIf Forms!FPayments!FPaymentSub.Form!PayType = _
"Check" And _
IsNull(Forms!FPayments!FPaymentSub.Form!CheckNo) Then
MsgBox "Need check number"
Cancel = True
End If

Hope This Helps,
Larry
 
D

Dave Elliott

I tried the code, but when I try to compile it, it goes to
Cancel=True Really just the Cancel part. ? Why is this ?

Thanks,

Dave
 

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