How do I call a procedure in Main form from sub-form?

D

Dennis

Hi,

I'm trying to call a procedure that resideds in the main from teh sub-form.
Here is the code in the main form:

Public Sub Check_Batch_Balance()

If IsNumeric(Me.txtDif) And Me.txtDif = 0 Then
Me.txtOutOfBalance.Visible = False
Else
Me.txtOutOfBalance.Visible = True
End If
End Sub


Here is the code in the sub-form:


Private Sub txtAmt1_AfterUpdate()

Call [frmContribute].Check_Batch_Balance '
Determine if batch is in balance

End Sub


When I run the code, I receive the following error message."

Access can't find the field "[" referred to in your expression. I have the
option to End, Debug, or Help. When I click on debug, it show the following
line:

Call [frmContribute].Check_Batch_Balance


What am I doing wrong and how do I correct it?
 
D

Dirk Goldgar

Dennis said:
Hi,

I'm trying to call a procedure that resideds in the main from teh
sub-form.
Here is the code in the main form:

Public Sub Check_Batch_Balance()

If IsNumeric(Me.txtDif) And Me.txtDif = 0 Then
Me.txtOutOfBalance.Visible = False
Else
Me.txtOutOfBalance.Visible = True
End If
End Sub


Here is the code in the sub-form:


Private Sub txtAmt1_AfterUpdate()

Call [frmContribute].Check_Batch_Balance '
Determine if batch is in balance

End Sub


When I run the code, I receive the following error message."

Access can't find the field "[" referred to in your expression. I have
the
option to End, Debug, or Help. When I click on debug, it show the
following
line:

Call [frmContribute].Check_Batch_Balance


What am I doing wrong and how do I correct it?


The easiest way is to access the Sub through the subform's Parent property,
which returns a reference to the subform's parent form:

Call Me.Parent.Check_Batch_Balance

If you needed to call it from some other location where you didn't have a
Parent reference, you could go through the Forms collection (so long as
frmContribute is open):

Call Forms!frmContribute.Check_Batch_Balance
 

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