L
Lisab
I am working with Access 2007 with linked Sybase tables
According to our new policy change, each user connected to the Sybase server
must be using their own assigned ID. Which means the application distributed
to the users must have a procedure to relink the tables using the users
provided id and password.
That code is working, however, some of the Sybase tables do not have a
primary key. When they were originally linked, the primary key(s) were
selected using the Access interface. Now, using this new code to relink the
tables, when i look at those tables in design view, for the newly relinked
table, I see no primary key.
1. what is the VBA code to identify if a table has a primary key
Here is my code -- Thank you
If Left$(.Connect, 4) = "ODBC" Then
strConnect = Left(.Connect, InStr(1, .Connect, "UID=") - 1)
& "UID=" & strUID & ";PWD=" & strPWD
Set tdf = DB.TableDefs(.Name)
tdf.Connect = strConnect
tdf.RefreshLink
'--------------------------------
'if table.name = one that need PrimaryKey reset then
'see if the table kept its primerykey, if so drop it
'run code to create new primerykey
'CREATE INDEX NewIndex ON <table_name>(<field_one>,
<field_two>) With PRIMARY
'end if
'--------------------------------
DB.QueryDefs.Delete ("qry_Test_ODBC_Links")
Set qdfNew = DB.CreateQueryDef("qry_Test_ODBC_Links",
"SELECT TOP 1 * FROM " & .Name)
If qdfNew.ReturnsRecords = False Then GoTo cErr
End If
According to our new policy change, each user connected to the Sybase server
must be using their own assigned ID. Which means the application distributed
to the users must have a procedure to relink the tables using the users
provided id and password.
That code is working, however, some of the Sybase tables do not have a
primary key. When they were originally linked, the primary key(s) were
selected using the Access interface. Now, using this new code to relink the
tables, when i look at those tables in design view, for the newly relinked
table, I see no primary key.
1. what is the VBA code to identify if a table has a primary key
Here is my code -- Thank you
If Left$(.Connect, 4) = "ODBC" Then
strConnect = Left(.Connect, InStr(1, .Connect, "UID=") - 1)
& "UID=" & strUID & ";PWD=" & strPWD
Set tdf = DB.TableDefs(.Name)
tdf.Connect = strConnect
tdf.RefreshLink
'--------------------------------
'if table.name = one that need PrimaryKey reset then
'see if the table kept its primerykey, if so drop it
'run code to create new primerykey
'CREATE INDEX NewIndex ON <table_name>(<field_one>,
<field_two>) With PRIMARY
'end if
'--------------------------------
DB.QueryDefs.Delete ("qry_Test_ODBC_Links")
Set qdfNew = DB.CreateQueryDef("qry_Test_ODBC_Links",
"SELECT TOP 1 * FROM " & .Name)
If qdfNew.ReturnsRecords = False Then GoTo cErr
End If