Errors when calling sub on different subform

  • Thread starter Thread starter cjg.groups
  • Start date Start date
C

cjg.groups

Hello,

When I try to call a subroutine on one subform from the parent form, I
get the error "Object doesn't support this property of method." Access
2003 is being used. Any suggestions would be appreciated.

The subroutine enables some controls on subform PaymentSubForm.
Changes to a control on the parent, OrderForm, should also enable those
subform controls. PaymentSubForm is open as a tab control within
OrderForm. The code is below.

Maybe it fails because the subform subroutine checks the parent form
control whose AfterUpdate is calling the subroutine..... Maybe I'm
just calling it wrong; I've seen four different methods in other
Newsgroup posts. In ToggleEnabled(), I even intentionally replaced Me
with the fully qualified form name since it only ever modifies that
form (but was that necessary?).

I know I should move ToggleEnabled to a module, but it seems more
organized to keep it with the form it modifies.


OrderForm:
Private Sub PaymentCheck_AfterUpdate()
Forms!OrderForm!PaymentSubForm.ToggleEnabled
End Sub


PaymentSubForm:
Public Sub ToggleEnabled()

conPaymentOK = "01 02 05"

Dim boolDidPay As Boolean

If IsNull(Forms!OrderForm!PaymentCheck) Then
boolDidPay = True
Else
boolDidPay = InStr(1, conPaymentOK,
CStr(Forms!OrderForm!PaymentCheck)) > 0
End If
Forms!OrderForm!PaymentSubForm!PayDate.Enabled = boolDidPay
Forms!OrderForm!PaymentSubForm!PayAmount.Enabled = boolDidPay
Forms!OrderForm!PaymentSubForm!PayCheckNo.Enabled = boolDidPay
End Sub


Thank you for your help.
 
It's a little hard to follow this, because there is no such object in Access
as a "Subform"... there is a Subform Control, into which a Form can be
embedded. The way to address the Form embedded in a Subform Control from the
parent form is:

Me.SubformControlName.Form

or, from elsewhere,

Forms!ParentFormName!SubformControlName.Form

But, I've never tried to do what you are wanting to do, so can't assure you
that it will work, even with the correct VBA code to refer to the Form
embedded in the Subform Control.

Larry Linson
Microsoft Access MVP
 
Ah, you reminded me how to fully qualify controls and things on forms
within subform controls. To access a control on a subform:

Forms!ParentFormName!SubformName.Form.Controls!ControlNameOnSubform

But here, I'm trying to call a subroutine on the form which is embedded
within a subform control. The following changes seemed to work:

In OrderForm, the parent form calling subform's subroutine:
Forms!OrderForm!PaymentSubForm.Form.ToggleEnabled

In PaymentSubForm, the subform's subroutine control fully qualified:
Forms!OrderForm!PaymentSubForm.Form.Controls!PayDate.Enabled =
boolDidPay
etc.


Now, I'd like to store this huge qualifier as a string for reuse within
the subprocedure. But this does not work:

Dim frm As String
frm = "Forms!OrderForm!PaymentSubForm.Form.Controls"
frm!PayDate.Enabled = boolDidPay

Could I use a With block around the code which needs the qualifier?

With Forms!OrderForm!PaymentSubForm.Form.Controls
!PayDate.Enabled = boolDidPay
!PayAmount.Enabled = boolDidPay
!PayCheckNo.Enabled = boolDidPay


And does this qualifier really slow down the code that much? Thanks.
 
To answer my secondary question: No, I can't seem to store the entire
qualifier as a string and use frm!PayDate.Enabled = boolDidPay. But I
can use the following With block:

With Forms!OrderForm!PaymentSubForm.Form.Controls
.Controls!PayDate.Enabled = boolDidPay
.Controls!PayAmount.Enabled = boolDidPay
.Controls!PayCheckNo.Enabled = boolDidPay
End With

Maybe not super efficient, but it works.
 
Back
Top