Option Strict On/Off

M

mconnolly4

Trying to create a primary key within a DAO access database from within VB
2005

The following code works but only if I turn off option strict

The line idxDesignTable.Fields.append(fldDesignIndex) is the source of the
problem.

Does anyone have an idea how I can recode to avoid the late bound issue

Thanks

Mike
'
'Create Primary Key Index Field
Dim idxDesignTable As Index
idxDesignTable = DesignTable.CreateIndex("KeyID" & "index")
Dim fldDesignIndex As Field
fldDesignIndex = idxDesignTable.CreateField("KeyID", dbLong)
idxDesignTable.Fields.append(fldDesignIndex) 'This line is the eror source
idxDesignTable.Primary = True
DesignTable.Indexes.Append(idxDesignTable)
'
 
A

Armin Zingler

mconnolly4 said:
Trying to create a primary key within a DAO access database from
within VB 2005

The following code works but only if I turn off option strict

The line idxDesignTable.Fields.append(fldDesignIndex) is the source
of the problem.

Does anyone have an idea how I can recode to avoid the late bound
issue

Thanks

Mike
'
'Create Primary Key Index Field
Dim idxDesignTable As Index
idxDesignTable = DesignTable.CreateIndex("KeyID" & "index")
Dim fldDesignIndex As Field
fldDesignIndex = idxDesignTable.CreateField("KeyID", dbLong)
idxDesignTable.Fields.append(fldDesignIndex) 'This line is the
eror source

Untested:

DirectCast(idxDesignTable.Fields, Fields).Append(fldDesignIndex)



Armin
 
M

mconnolly4

Armin

Thanks, tried to use and following error
'unable to cast COM object type System COM to DAO.Fields

Any other suggestions - this has really got me baffled as fields is a member
of DAO.Index

Mike
 
A

Armin Zingler

mconnolly4 said:
Armin

Thanks, tried to use and following error
'unable to cast COM object type System COM to DAO.Fields

Any other suggestions - this has really got me baffled as fields is
a member of DAO.Index

Probably must be IndexFields:

DirectCast(idxDesignTable.Fields, IndexFields).Append(fldDesignIndex)

(still untested...)


Armin
 
M

Michael D. Ober

Instead of DirectCast, use the VB pseudo function CType.

CType(idxDesignTable.Fields, Fields).Append(fldDesignIndex)

If this doesn't work, use the object browser to the the actual type for
idxDesignTable.Fields and use CType to cast to it.

Mike Ober.
 
M

mconnolly4

Armin

One more question please - where di you find the term "IndexFields" it
doesn't appear in object browser

Thanks again

Mike
 
A

Armin Zingler

mconnolly4 said:
Armin

One more question please - where di you find the term "IndexFields"
it doesn't appear in object browser

It does appear if you don't hide these members (in the object browser at the
top right there's a drop down menu where you can hide these types and
members).
I wondered which type it could be if not "Fields", so I've searched for
"Append" and found "IndexFields". Obviously that's the one.


Armin
 
M

mconnolly4

Armin

Thanks - really appreciate the help

Mike

Armin Zingler said:
It does appear if you don't hide these members (in the object browser at
the top right there's a drop down menu where you can hide these types and
members).
I wondered which type it could be if not "Fields", so I've searched for
"Append" and found "IndexFields". Obviously that's the one.


Armin
 

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