Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange DAO behaviour when building a tabledef

200 views
Skip to first unread message

The Frog

unread,
Apr 26, 2011, 8:41:47 AM4/26/11
to
Hi Everyone,

I am having a strange error (3001, Invalid Argument) when trying to
build a DAO.Tabledef object. I could have sworn that the code I am
using I have used before. I am trying to create a copy of a tabledef,
using a new name, for a linked ODBC table (using a DSNless connect
string). I am seemingly unable to set the attributes of the tabledef
object and keep erroring out when I try to do so. It makes absolutely
no sense to me why....can anyone show me the way?

Here is the code (pretty damn simple):

Set oDef = New DAO.TableDef 'create our new
tabledef
With oDef
.Name = "tmp"
.Connect = ConnectString 'set the new
connection string
.SourceTableName = Src 'replace the
source table details
.Attributes = dbAttachedODBC Or dbAttachSavePWD 'replace the
attributes
End With

oDefs.Append oDef 'attach the
definition to the database

The variables for Src and ConnectString are both string objects and
appear to be able to be correctly implemented when using the code.
The .Attributes = dbAttachedODBC Or dbAttachSavePWD line is the one
producing the error. The Long equivalent of those two values 'Or'd' is
537001984 if you need it.

I had a look at Doug Steele's stuff on reconnecting ODBC linked tables
with SQl Server and he approaches this the same way (he takes the
value from the old table and then puts the long value into the new def
before appending it to the collection). Doug actually has an error in
his addendums on the topic where he states that the values are
'And'ed' together but in fact they must be Or'd (or else you will end
up with a value of 0).

Any help greatly appreciated.

Cheers

The Frog
(A2003 on WinXP - sorry, forgot to mention)

The Frog

unread,
Apr 26, 2011, 9:34:46 AM4/26/11
to
Never mind, figured it out. Firstly, setting the attributes needs to
be done after the table is appended. Secondly, if you are using a
DSNless connect string then trying to set the dbAttachSavePWD is
pointless as it is there anyway (if it is part of your string it will
be saved). Thirdly, the dbAttachedODBC is set automatically as an
attribute if you have your connect string and source table string
entered correctly at the time the tabledef is appended.

So:

Set oDef = DBEngine(0)(0).CreateTableDef


With oDef
.Name = "tmp"
.Connect = ConnectString 'set the new
connection string
.SourceTableName = Src 'replace the source
table details

End With

oDefs.Append oDef 'attach the
definition to the database

And we are done and dusted :-)

Sorry for the silly question. I was simply not paying enough attention
to what I was typing in - need much more coffee.....

Cheers

The Frog

0 new messages