DisplayControl property on a field using DAO in C#

G

Guest

Hello,

I am trying to set the DisplayControl property on a field using DAOin
C#. I've found lots of sample code for VB and am trying to adapt it
for use in C#.

This is the code I'm running now:

DAO.Field f = db.TableDefs[TableName].Fields­[ColumnName];

//110 is list box
DAO.Property p1 = f.CreateProperty("DisplayContr­ol", Type.Missing ,
110, Type.Missing);
f.Properties.Append( p1 );

This is the error:

[COMException (0x800a0d3a): Property 'Value' must be set before using
this method.] DAO.Properties.Append(Object Object) +0

The third parameter in the CreateProperty method is the value, so I
don't know why it's not being set.

Any help figuring this out would be greatly appreciated.
 
P

Paul Overway

You're not likely to get much help with C# in this forum....VBA? Yes.

Even though the error says Value, I'd suspect the Type parameter. Try
passing a 3 for the Type parameter.
 
G

Guest

Thanks for the tip. Unfortunately, using 3 for the type causes another
runtime exception:
[COMException (0x800a0d5d): Data type conversion error.]
DAO.FieldClass.CreateProperty(Object Name, Object Type, Object Value,
Object DDL) +0

I tried a few other values including
System.Type.GetType("System.Int32")
System.Type.GetTypeCode(System.Type.GetType("System.Int32"))

This is the line of code:
DAO.Property p1 = f.CreateProperty("DisplayControl",
System.Type.GetTypeCode(System.Type.GetType("System.Int32")) , 110,
Type.Missing);
f.Properties.Append( p1 );


Does anyone know what this parameter is expecting to recieve or have
recomendations about where to look to find info on this question?

Thanks!


Paul Overway said:
You're not likely to get much help with C# in this forum....VBA? Yes.

Even though the error says Value, I'd suspect the Type parameter. Try
passing a 3 for the Type parameter.

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


L Magarian said:
Hello,

I am trying to set the DisplayControl property on a field using DAOin
C#. I've found lots of sample code for VB and am trying to adapt it
for use in C#.

This is the code I'm running now:

DAO.Field f = db.TableDefs[TableName].Fields­[ColumnName];

//110 is list box
DAO.Property p1 = f.CreateProperty("DisplayContr­ol", Type.Missing ,
110, Type.Missing);
f.Properties.Append( p1 );

This is the error:

[COMException (0x800a0d3a): Property 'Value' must be set before using
this method.] DAO.Properties.Append(Object Object) +0

The third parameter in the CreateProperty method is the value, so I
don't know why it's not being set.

Any help figuring this out would be greatly appreciated.
 
M

Mark Burns via AccessMonster.com

The problem appears to be with the CreateProperty call.
A few key points from The Access 2002 help for this read:
(Comments inline below denoted thus: <*** my stuff ***>)
<quote>
CreateProperty Method

Creates a new user-defined Property object (Microsoft Jet workspaces only).

Syntax

Set property = object.CreateProperty (name, type, value, DDL)

The CreateProperty method syntax has these parts.

Part Description
name Optional. A Variant (String subtype) that uniquely names the new
Property object.

type Optional. A constant that defines the data type of the new Property
object. See the Type property for valid data types.
<*** this will need to be a type as defined in the DAO .DLL, a DataTypeEnum
- not a .net system.(whatever) framework type ***>

value Optional. A Variant containing the initial property value. See the
Value property for details.

DDL Optional. A Variant (Boolean subtype) that indicates whether or not the
Property is a DDL object. The default is False. If DDL is True, users can't
change or delete this Property object unless they have dbSecWriteDef
permission.
<*** Shouldn't you be setting this TRUE for your purposes here? ***>

Remarks
<snip>
Note If you omit the DDL argument, it defaults to False (non-DDL). Because
no corresponding DDL property is exposed, you must delete and re-create a
Property object you want to change from DDL to non-DDL.
</quote>
 

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