Enable/disable controls in subform

G

Guest

I am getting a non-specified runtime error on Access 2003 runtime only (can't
duplicate on my development station) under this circumstance:

In my Form_Current, I call a sub that enables/disables certain controls
based on contents of other controls. Some of the controls that I
enable/disable are on a subform.

It fails on the second line below (ProductID1 is a control on the form,
TripDetail is the name of the subform, and BundlesProduct1 is a control on
the subform):

If IsNull(ProductID1) Then
Me.TripDetail!BundlesProduct1.Enabled = False
Else
Me.TripDetail!BundlesProduct1.Enabled = True
End If

The code runs fine when I open the form, but not after going to a new record.
 
A

Allen Browne

Suggestions:

1. Include the .Form bit:
Me.TripDetail.Form!BundlesProduct1.Enabled = False
Especially with A2003, that helps.

2. If BundlesProduct1 happens to be the ActiveControl of TripDetail.Form,
the attempt to disable it could fail.

3. If the subform has no records (probably the case if the main form is at a
new record), AND no new records can be added, the detail section of the
subform goes completely blank. Referring to the non-existent control in the
subform then generates an error.

Example of when the subform could not add new records:
- Its AllowAdditions property is No.
- The subform is based on a non-updatable query.
- The user does not have permissions to add records.
- The main form was opened with AllowEdits as No, so it does not allow
changes in the subform either.
 
G

Guest

Thank you for the help, Allen. #2 appears to be the solution. This was one of
the first things I attempted to fix by moving the focus to an object on the
parent form before I ran the code. However, I did not realize that a subform
object retained the focus when leaving the subform. This explains why the
error was occurring regardless of which main form control had the focus; the
subform focus was on one of the affected boxes (that one was just one example
of five).

Curiously, I was unable to duplicate the error with my dev workstation, and
the error-trapping in the runtime was unable to correctly identify the error
for some reason.

Do you have a better solution than my (probably rather clumsy) one now of
changing the focus to the first (unaffected by the enable/disable code)
control in the subform, then to the first control on the parent form in the
parent form's Current event, just before calling the sub that enables/disbles
the subform controls?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top