Programmatically setting a Form's Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

According to the MSDN Library, a Microsoft.Office.Interop.Access.Form
object's Name property (or .Properties("Name").Value) is read/write. Were
this true, it would make creating and saving a Form quite straightfoward.

Unfortunately, when I actually try to set the Name property from code (.NET
2.something), I'm presented with an "unhandled COMException" informing me
that "This property is read-only and can't be set." Nothing I've been able to
find in the MSDN Library, or any forums, addresses this.

The version of Access in question is 2003 (11.8166.8172). The only
documentation I've been able to find, despite extensive searching, is for
Access 2007. Therefore, I can't quite call this a case of misdocumentation,
but in any case, I'm stuck between 1. having programmatically-generated forms
be named things like Form51, or 2. forcing the enduser to manually enter a
name...for each of a potentially quite large and complicated list of forms.
Neither is acceptable.

Any suggestions?
 
FWIW:

Within Access, the following works:
DoCmd.Rename "NewName", acForm,"OldName"

The following does not:
DoCmd.OpenForm "OldName", acDesign '(acNormal fails on next line
as well)
Forms("OldName").Name = "NewName" 'ReadOnly error

CurrentProject.AllForms("OldName").Name = "NewName" 'ReadOnly error


In the Access model a Form object is a member of the Forms collection but
the Forms collection consists *only of open forms*. Saved forms would be a
member of the AccessObject.AllForms collection:
Application.CurrentProject.AllForms("myForm")

Access 2003 VBA Help file specifies that Name is read-write for a Form but
Read-only for an AccessObject. The inference I got from that is that the
form has to be open in order to change the name, but, as evidenced above,
that doesn't seem to be the case.

Good Luck & HTH,
George
 
I'm trying to create an Access Form using .NET code, reading all properties
required for the form and its controls from a separate database.

I'm aware of the Forms collection being not only something other than Form
objects (I have no idea why, but my code deals with it, if a bit hackishly),
but only open ones. But I don't reference this collection. My code is in this
form:

Form foo = DB.CreateForm(); //DB is an Access Application object
foo.Name = somestring;

The last line throws the exception, as does foo.Properties("Name").Value =
somestring;.

I got around this problem by calling DB's DoCmd methods OpenForm, Save,
Close, and Rename (in that order), but I'm still curious about the potential
misdocumentation, and also why there appears to be no Access 2003 Developer
Reference on MSDN.
 
Since 2007 is the current version, most of the documentation will be on that
version.
It seems it would take a lot of code to create a fully functioning Access
form. Why not just create the form the normal design view way?
Pardon my lack of vision, but I don't see what this will accomplish for you.
 
Back
Top