Invalid Object Reference

  • Thread starter Thread starter G Bramfield
  • Start date Start date
G

G Bramfield

Hello. I am working with an Access2000 db. My problem is with a main
form/sub form, with a two part primary key. The Link Child/Master fields
are set correctly, however, when I go to enter a record into the subform,
Access says "You tried to run a Visual Basic procedure that improperly
references a property or method of that object". There is no VB procedure
attached to the form. If you enter the data directly from the tables, the
information appears as it should in the mainform/subform. At first, I
thought I had a missing reference in my tools/references section. I tried
adding some references, but nothing worked. Any suggestions would be great!

Regards,
Gord.
 
First thing to check is the foreign key field:
1. Open the subform's table in design view.
2. Select the field that relates to the main form's table.
3. Delete the zero from the field's Default Value property (lower pane).
4. Consider setting the field's Required property to Yes, if it would be
wrong to have a child record where this field is blank. (Referential
integrity alone does not prevent this.)
5. Save the table.

If that does not fix the problem, is the subform based on a query? What
tables are in the query? What fields are exposed to the form? Particularly,
you must have the foreign key field of the related table in the subform's
recordsource, and not another field with the same name (such as the primary
key of the main form's table). If that still doesn't work, try putting this
foreign key field onto the form and watch its state when the error occurs.

If you are still stuck and you are certain that there are no procedures at
all in the subform's module, open the subform itself in design view directly
from the Database window. Set its HasModule property to No.
 
Hi Allen. Thank you for your reply. Unfortunately, everything you
suggested I have already tried. I am perplexed as to why Access is
complaining about this. This is a simple mainform/subform. The only
difference is the two part primary key. Furthermore, even though each
form/subform does not have a module, Access is still complaining that a VB
procedure is improperly trying to reference a property or method of that
object.

One thing weird I did notice, however, was that when I tried to enter a
record into the the subform, the botton of the form read Calculating.....
It is as if Access is trying to evaluate an expression. The VB error occurs
at the same time.

Gord.
 
Okay. Some more ideas to help debug this:

1. Let's eliminate Name AutoCorrect as a possible cause. Uncheck the boxes
under this heading in Tools | Options | General. Then compact the database.

2. Remove any conditional formatting you are using. It can cause the endless
calculating.

3. If Access is complaining about a VB error, it would be worth checking
that your references are correct. From any code window, choose References
from the Tools menu. Check that none are missing. Remove any unnecessary
references: hopefully can get down to just 3 (Access, VBA and either DAO or
ADO). Then check that it compiles properly (Debug menu).

4. Two part primary key: That's probably important. Presumably you have 2
fields nominated in the LinkMasterFields, and two in the LinkChildFields.
Make sure there are actually text boxes on the subform for the two fields,
so you can watch what is happening.

5. Error message: At what point does this message appear? When you begin to
add a record, or when Access tries to save the record? Is there an error
number? Any indication of what object?

6. If the subform is based on a query, try adding a record directly to the
query. Do you get the same error? If so, then the problem is with what JET
is trying to do, and not with the form/subform.
 
Hi Allen.

1,2,3 have been addressed, and nothing of any value has been observed.

4. The two part primary key consists of CourseID and Section. When Access
created the mainform/subform, both parts were put into the Link Child/Master
fields. When I view the form in form view, the Section field has ' #Error '
in the field rather than the corresponding value from the Section field in
the main part of the form. However, I can solve this problem by simply
referencing the Section field of the main part of the form by using
forms!MainFormName!Section in the Link Master Field. Once this has been
implemented, the #Error reading goes away, and the appropriate value for
Section is now in its place. Unfortunately, this does not solve the larger
problem. I still get the VB object refererence error.

5. This error message happens the instant I attempt to enter a value into
one of the fields of the subform. There is no error number, and no
reference to a specific object, just a pop up message advising of the
improper reference.

6. The subform is not based on a query. However, while trouble shooting
this problem, I did change the record source to be query just to see if
there were any changes. Unfortunately, I got the same behaviour.

What is interesting is that I can open the subform by itself and
successfully enter a record with no problem-assuming I do not violate any
integrity rules. Therefore, Access must not like the linking of the
mainform/subform of the two part primary key. When I reduce the two part
key to only one part, it works fine. However, a two part key is not
appropriate in this situation.

Anyway, I look forward to your reply.

Gord.
 
Correction: a one part primary key is not appropriate in this situation.
Sorry about that.

Gord.
 
Okay, good. This is getting narrowed. The fact that the subform accepts
records on its own indicates the problem is with the interpretation of the
link between main form and subform.

Forms have a property named Section. Is it possible that Access is confusing
the field named "Section" with the form's property named "Section"?
 
Back
Top