Jet doesn't recognize my subform

  • Thread starter Thread starter elizabeth baker
  • Start date Start date
E

elizabeth baker

i have recently begun using Access 2002 on a database written in Access
2000 originally and converted. i need to set the source of a subform by
code:

Forms!frmName!sfrmName.SourceObject = tblName

For the ease of the group, i am using generic names like frmName,
sfrmName and tblName.

If i understood the help files correctly, the RecordSource property has
been replaced by SourceObject. Am i correct in this?

i keep getting the error message

Run-time error '3011':
The Microsoft jet database engine could not find the object
'sfrmName'. Make sure the object exists and that you spell its
name and the path name correctly.

The subform exists in the database window and holds the appropriate
data. i have written code to check that it's there and open it for
testing, which works. Why isn't Access seeing it?

i have also tried the following code (stabbing in the dark here), also
with no success:

Me!sfrmCCBillImport.SourceObject = tblName
Me!sfrmCCBillImport.Form.RecordSource = tblName

Any ideas? Thanks for your help.

--e (elizabeth)
 
SourceObject and RecordSource are different.

A form has a RecordSource property.
You can set the RecordSource to the name of a table or query that should
supply records for the form. Alternatively, the RecordSource can be a SQL
statement.

A subform control has a SourceObject property.
You can set the SourceObject to the name of a *form* - what form Access
should show in the subform control.

If the SourceObject of a subform has been set (i.e. there is a nominated
form in the subform control), then it contains a form and that form can have
a RecordSource.
 
If what you've give us is true, then here's your problem:

You need to put your table name in quotes.

Forms!frmName!sfrmName.SourceObject = "tblName"

Actually, I think I've used a reference to the form the
Subform is based on's RecordSource, not SourceObject which
would simply be another form.

I've also created two IDENTICAL subforms, one named
Subform1 and the other, Subform2, but both based on two
different queries, thus giving me two different results.
Then, I simply load the appropriate subform through code
when the mainform opens, or when I click a button. In
this case, I would be changing the subform's
SourceObject. You can use this to switch between one form
to view info and another to input info. without having to
actually open/close the main form.
 
Thanks, Allen, for your response. However, i believe i may not have
stated my problem adequately. Setting the RecordSource/SourceObject does
not seem to be the problem, or, i guess i should say, my program doesn't
get that far. It is the subform itself that is not recognized, as if the
Jet engine does not recognize the subform as being a part of the Forms
collection.

Thanks, --e
 
Thanks, DanK. Actually, in this case, tblName is a string variable
(holding the table name) i am using throughout the code, so i don't
think the quotes would be the problem.

i responded to Allen's message as follows:

i believe i may not have stated my problem adequately. Setting the
RecordSource/SourceObject does not seem to be the problem, or, i guess i
should say, my program doesn't get that far. It is the subform itself
that is not recognized, as if the Jet engine does not recognize the
subform as being a part of the Forms collection.

Thanks, --e
 
Thanks, Allen, for your response. However, i believe i may not have
stated my problem adequately. Setting the RecordSource/SourceObject
does
not seem to be the problem, or, i guess i should say, my program
doesn't
get that far. It is the subform itself that is not recognized, as if
the
Jet engine does not recognize the subform as being a part of the Forms
collection.

A subform is *not* part of the Forms collection, but that fact seems
irrelevant in this case since the example code you posted,

Forms!frmName!sfrmName.SourceObject = tblName

, isn't trying to reach the subform through the Forms collection.
Rather, it reaches the *form* ("frmName") through the Forms collection,
and the subform ("sfrmName") control through the Controls collection of
the form. This is perfectly correct syntax (though Allen is right in
what he says about SourceObject vs. RecordSource.

However, you may be mistakenly using the name of the subform's
source-object form when you should be using the name of the subform
*control* on the main form. In other words, "sfrmName" in the above
statement must be the name of the subform *control* on the main form --
the "window: in which the subform is to be displayed -- which is not
necessarily the name of the form object that is to be displayed in that
window. Depending on how the subform control was created, the two names
may be the same or different.

Suppose you have a main form named "MainForm", and on this form you have
a subform control named "SubformControl", with its SourceObject property
set to display a form named "sfMySubform". To set the recordsource of
the subform to a table named "tblName", you would use a statement like
this:

Forms!MainForm!SubformControl.Form.RecordSource = "tblName"

Note that the actual name of the subform's SourceObject doesn't appear
at all.

If all of these names are actually specified as string variables, you
have to use a slightly different syntax. For example:

Dim strMainForm As String
Dim strSubformControl As String
Dim strTableName As String

' ... set variable values ...

Forms(strMainForm).Controls(strSubformControl).Form.RecordSource =
strTableName


Does that clear things up?
 
Back
Top