expression contains an illegal reference to the property Form / Subform

  • Thread starter Thread starter Mr. T.
  • Start date Start date
M

Mr. T.

Hi,

i've got a form that i open in 2 different ways.

One way is to "browse" through the records. Therefore i use the following
code in my main screen:

DoCmd.OpenForm "MyForm", acNormal, , , acFormEdit, acDialog, "BROWSE"

The second way is to go directly to a specific screen. Therefore i made a
search screen (no problem there) and when i want to open the form i use the
following line of code:

DoCmd.OpenForm "MyForm", acNormal, , , acFormEdit, acDialog, Me!MyListBox

when the form opens in the first way (to browse) everything goes fine. But
when i open the form in the second way, i get the error that the expression
contains an illegal reference to the property Form / Subform. I get this on
a line of code in the Form.Current. In that form, depending on the type of
record it is, i want to show or hide some field on a subform. So i added the
following line of code to the Form.Current:

IF MyCriterium THEN
Me.MySubForm.Form!MySubFormField.Visible = True
ELSE
Me.MySubForm.Form!MySubFormField.Visible = False
END IF

That's the line i get the above mentioned error on. Is anyone able to tell
me what i'm doing wrong?

Regards,

Thomas
 
i am not sure. try specifically testing for openargs ie if openargs = xxxxx
, rather than your variable mycriterion when you open the form, and see how
it is getting stopped. also click on the left margin at the problem line or
just before, and a brown blob will be entered. This will halt the code, and
you can then use F8 to step through code a line at a tine. You can also hover
over variables, and see how they change.

finally i am not sure but maybe passing the control name passes the control
rather than a value, so try saving the field value in a string or number
variable, and passing that rather then the control itslef. Hope this helps
 
Is it possible Me!MyListBox is null at the time of the openform? If it's a
listbox, make sure a row is selected (the listbox control will have a
value).
 
Back
Top