vbams-access

Referring to a subform as recommended produces an error


These two lines of code should produce the same result.

Debug.Print Forms!DocLoader!DL_RowBox!DLR_FileName.Name
Debug.Print Forms!DocLoader!DL_RowBox.Form!DLR_FileName.Name

The first line, using only default parameters, seems to work no matter the context.

The second one, recommended in almost every VBA reference, including the answer being suggested from SO as I type this, follows this structure:

Debug.Print Forms![Form Name]![Subform Control Name].Form![Control Name].Name

The second recommended syntax, unless in design view, throws

error 40036, "Application-defined or object-defined error"

I cannot use it at runtime.

I tried combinations of bang and period. I tried enclosing field names in brackets.

The common denominator is that as soon as I reference .Form the application throws an error. Something simple like .Form.Caption has thrown an error.

  1. Are there any other ways of referring to a subform's form properties, since I need these as well as its controls
  2. Why does the first line execute while the second, recommended one does not?

Solution

  • Running the compiler appears to have fixed the issue.