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)
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