PC Review


Reply
Thread Tools Rate Thread

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

 
 
Dennis
Guest
Posts: n/a
 
      22nd May 2010
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?





--
Dennis
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      22nd May 2010
"Dennis" <(E-Mail Removed)> wrote in message
news:8800D461-DAEE-4F5B-85F3-(E-Mail Removed)...
> 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

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      22nd May 2010
Dirk,

That worked great!

Thanks.

Dennis
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Can Subform Call Main Form Sub Procedure Jeanette Cunningham Microsoft Access Forms 0 2nd Oct 2009 04:14 AM
Procedure call to Main Form from subform fires once but not thereafter rwfreeman Microsoft Access Form Coding 2 24th May 2007 12:49 PM
Call subform event procedure from main form event procedure ? =?Utf-8?B?cGxj?= Microsoft Access Form Coding 2 26th Oct 2006 10:15 PM
CALL a dialog form just after the main form is loaded. Microsoft VB .NET 1 3rd May 2006 06:25 PM
Call procedure from form MKM Microsoft Access VBA Modules 1 27th Sep 2003 03:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.