CreateTableDef 'attributes' option 
Author Message
 CreateTableDef 'attributes' option

I am trying to link an ODBC table to a database using CreateTableDef.

When I use the optional attribute of dbAttachSavePWD it works fine, but
there are times when I don't want to save the password.

The help subject on CreateTableDef lists valid attributes such as
dbAttachedODBC, but anything other than dbAttachSavePWD generates an error
3001 - Invalid argument.

Am I doing something wrong here?

Thanks,

Glenn.

Here is my code...

Public Function ConnectODBCtable(UseDatabase As String, _
  KeepOld As Boolean, DSN As String, _
  TableName As String, SourceTable As String, _
  Optional UID As String, Optional PWD As String) As String

    Dim dbs As Database
    Dim tdf As TableDef
    Dim OldLink As String
    Dim ConnectString As String

    On Error GoTo ConnectODBCtableError

    Set dbs = OpenDatabase(UseDatabase)

    ' Rename old link
    OldLink = TableName & "_" & Format(Now(), "YYYYMMDDHHNNSS")
    'DoCmd.Rename OldLink, acTable, TableName
    dbs.TableDefs(TableName).Name = OldLink

    ' Link new table
    ConnectString = "ODBC;" & "DSN=" & DSN & ";"
    If IsMissing(UID) = False Then
        ConnectString = ConnectString & "UID=" & UID & ";"
    End If
    If IsMissing(PWD) = False Then
        ConnectString = ConnectString & "PWD=" & PWD & ";"
    End If

    Set tdf = dbs.CreateTableDef(TableName, dbAttachSavePWD, SourceTable,
ConnectString)
    dbs.TableDefs.Append tdf

    ' Delete old link if required
    If KeepOld = False Then DoCmd.DeleteObject acTable, OldLink

    ConnectODBCtable = "OK"

ConnectODBCtableExit:
    dbs.Close
    Set dbs = Nothing

Exit Function

ConnectODBCtableError:
    ConnectODBCtable = "Error - " & Err.Number & " - " & Err.Description
    Resume ConnectODBCtableExit

End Function



Tue, 06 Jan 2004 09:57:00 GMT  
 CreateTableDef 'attributes' option
HA!   I had similar problems, and somebody here implied that I
was stupid (I am but that is another story).

Use 0 (zero) for the attribute.  You can't use dbAttachedODBC,
and you can't have the parameter missing.

(david)

Quote:

> I am trying to link an ODBC table to a database using CreateTableDef.

> When I use the optional attribute of dbAttachSavePWD it works fine, but
> there are times when I don't want to save the password.

> The help subject on CreateTableDef lists valid attributes such as
> dbAttachedODBC, but anything other than dbAttachSavePWD generates an error
> 3001 - Invalid argument.

> Am I doing something wrong here?

> Thanks,

> Glenn.

> Here is my code...

> Public Function ConnectODBCtable(UseDatabase As String, _
>   KeepOld As Boolean, DSN As String, _
>   TableName As String, SourceTable As String, _
>   Optional UID As String, Optional PWD As String) As String

>     Dim dbs As Database
>     Dim tdf As TableDef
>     Dim OldLink As String
>     Dim ConnectString As String

>     On Error GoTo ConnectODBCtableError

>     Set dbs = OpenDatabase(UseDatabase)

>     ' Rename old link
>     OldLink = TableName & "_" & Format(Now(), "YYYYMMDDHHNNSS")
>     'DoCmd.Rename OldLink, acTable, TableName
>     dbs.TableDefs(TableName).Name = OldLink

>     ' Link new table
>     ConnectString = "ODBC;" & "DSN=" & DSN & ";"
>     If IsMissing(UID) = False Then
>         ConnectString = ConnectString & "UID=" & UID & ";"
>     End If
>     If IsMissing(PWD) = False Then
>         ConnectString = ConnectString & "PWD=" & PWD & ";"
>     End If

>     Set tdf = dbs.CreateTableDef(TableName, dbAttachSavePWD, SourceTable,
> ConnectString)
>     dbs.TableDefs.Append tdf

>     ' Delete old link if required
>     If KeepOld = False Then DoCmd.DeleteObject acTable, OldLink

>     ConnectODBCtable = "OK"

> ConnectODBCtableExit:
>     dbs.Close
>     Set dbs = Nothing

> Exit Function

> ConnectODBCtableError:
>     ConnectODBCtable = "Error - " & Err.Number & " - " & Err.Description
>     Resume ConnectODBCtableExit

> End Function



Wed, 07 Jan 2004 15:52:06 GMT  
 CreateTableDef 'attributes' option
I did not imply you were stupid, I did imply that obsessing over language
that is not unclear unless you insist on being stubborn does waste time. I
guess you need to learn that if something does not work you might have to
let go of your assumptions? :-)

When thinks work, you can assume you are right --- the rest of the time you
need to doubt yourself a bit more!

--
MichKa

the only book on internationalization in VB at
http://www.i18nWithVB.com/



Quote:
> HA!   I had similar problems, and somebody here implied that I
> was stupid (I am but that is another story).

> Use 0 (zero) for the attribute.  You can't use dbAttachedODBC,
> and you can't have the parameter missing.

> (david)




Quote:
> > I am trying to link an ODBC table to a database using CreateTableDef.

> > When I use the optional attribute of dbAttachSavePWD it works fine, but
> > there are times when I don't want to save the password.

> > The help subject on CreateTableDef lists valid attributes such as
> > dbAttachedODBC, but anything other than dbAttachSavePWD generates an
error
> > 3001 - Invalid argument.

> > Am I doing something wrong here?

> > Thanks,

> > Glenn.

> > Here is my code...

> > Public Function ConnectODBCtable(UseDatabase As String, _
> >   KeepOld As Boolean, DSN As String, _
> >   TableName As String, SourceTable As String, _
> >   Optional UID As String, Optional PWD As String) As String

> >     Dim dbs As Database
> >     Dim tdf As TableDef
> >     Dim OldLink As String
> >     Dim ConnectString As String

> >     On Error GoTo ConnectODBCtableError

> >     Set dbs = OpenDatabase(UseDatabase)

> >     ' Rename old link
> >     OldLink = TableName & "_" & Format(Now(), "YYYYMMDDHHNNSS")
> >     'DoCmd.Rename OldLink, acTable, TableName
> >     dbs.TableDefs(TableName).Name = OldLink

> >     ' Link new table
> >     ConnectString = "ODBC;" & "DSN=" & DSN & ";"
> >     If IsMissing(UID) = False Then
> >         ConnectString = ConnectString & "UID=" & UID & ";"
> >     End If
> >     If IsMissing(PWD) = False Then
> >         ConnectString = ConnectString & "PWD=" & PWD & ";"
> >     End If

> >     Set tdf = dbs.CreateTableDef(TableName, dbAttachSavePWD,
SourceTable,
> > ConnectString)
> >     dbs.TableDefs.Append tdf

> >     ' Delete old link if required
> >     If KeepOld = False Then DoCmd.DeleteObject acTable, OldLink

> >     ConnectODBCtable = "OK"

> > ConnectODBCtableExit:
> >     dbs.Close
> >     Set dbs = Nothing

> > Exit Function

> > ConnectODBCtableError:
> >     ConnectODBCtable = "Error - " & Err.Number & " - " & Err.Description
> >     Resume ConnectODBCtableExit

> > End Function



Wed, 07 Jan 2004 17:00:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Can't see a database table's attributes

2. default 'option explicit on' and 'option strict on'

3. Option Groups 'Why No SetFocus'

4. 'keep track of formatting' option

5. 'Create Symbolic Debug Info' option

6. 'Create Symbolic Debug Info' option

7. Can't identify 'Scope' or 'Headers' attributes in DOM object

8. **************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Help me !!!!!!!!!!!!!!!!!!!!!!!!'''''''''''''''''''''''*************

9. How to get value of the object's attribute ,the object's attribute is specified by a string variable ?

10. How to get value of the object's attribute ,the object's attribute is specified by a string variable ?

11. What's the clas attribute?

12. COM+ package no 'start', 'down' option when right click it

 

 
Powered by phpBB® Forum Software