Frustrated with getting VBA syntax wrong...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

.... this code just produces an error "what's this form then? I can't find it!"

Why won't it work?

Public Function SubExp() As Boolean
Dim SubForm As Access.Form
Set SubForm = Application.Forms("sub_Order_Detail")
If SubForm.SubdatasheetExpanded Then
SubExp = True
Else
SubExp = False
End If
End Functio
 
Vaughan said:
... this code just produces an error "what's this form then? I can't find
it!"

Why won't it work?

Public Function SubExp() As Boolean
Dim SubForm As Access.Form
Set SubForm = Application.Forms("sub_Order_Detail")
If SubForm.SubdatasheetExpanded Then
SubExp = True
Else
SubExp = False
End If
End Functio

Do you have a form named sub_Order_Detail (including the underlines)?
That's the form it's looking for.

Tom Lake
 
Vaughan said:
... this code just produces an error "what's this form then? I can't
find it!"

Why won't it work?

Public Function SubExp() As Boolean
Dim SubForm As Access.Form
Set SubForm = Application.Forms("sub_Order_Detail")
If SubForm.SubdatasheetExpanded Then
SubExp = True
Else
SubExp = False
End If
End Functio

If "sub_Order_Detail" is only open as a subform on a parent form, then
it's not a member of the Forms collection. Subforms can only be
accessed through the subform control on the parent form. For example,
if this subform is on a main form named "form_Order", and if the subform
control on that form is also named "sub_Order_Detail", like the form it
displays, then you might write it like this:

Set SubForm = _

Application.Forms("sub_Order_Detail").Controls("sub_Order_Detail").Form

As you see, you must go through the Form property of the subform control
on the main form. Be aware that the subform control may not have the
same name as the form that is its Source Object -- you have to check
that, and use the control name, not the form name, if they are
different.
 
Thanks for the input Tom. In fact I have chcked the form name very carefully.

Thanks

Vaughan
 
Thanks Dirk

This looks extremely promising. I'll give it a try and let you know how I
got on.

Thanks

Vaughan
 
Back
Top