473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Primary key of SQL Server linked View in an Access Database

Hi,

I've encountered difficulties in maintaining the primary key of a SQL
Server view linked dynamically in VBA to an Access database. If I use
the transferDatabase function, then the user is prompted to choose the
unique identifyer. If I create the link via the ADOX catalog, then the
key is lost and the data isn't updatable. The goal is to create a
dynamically linked updatable view without prompting the user.

Any suggestions?

By the way, here is the code I've used:
----------------------------------------

Public Function viewLinkTest()

Dim sConn As String
Dim cnn As New ADODB.Connection

cnn.Open "DSN=DSN_Name"
sConn = "ODBC;Driver={SQL
Server};Server=serverName;DATABASE=SQLdbName"

DoCmd.TransferDatabase acLink, "ODBC Database", _
sConn, acTable, vwName, linkedTableName

cnn.Close

End Function
-----------------------------------------

Public Function adoxLinker()

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim strLinkName, strTableName, sConn As String

sConn = "ODBC;Driver={SQL
Server};Server=serverName;DATABASE=SQLdbName"
strLinkName = "viewName"
strTableName = "localName"

On Error Resume Next
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(strLinkName)
If Err = 0 Then
cat.Tables.Delete (strLinkName)
Else
Err = 0
End If

tbl.Name = strLinkName
Set tbl.ParentCatalog = cat

tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = _
"ODBC; DSN = " & sConn
tbl.Properties("Jet OLEDB:remote Table Name") = strTableName
cat.Tables.Append tbl

Dim k As New Key

'''' Tried to create a unique key, but didn't manage to do so
' k.Columns = "tblID"
' k.Name = "tblID"
' k.Type = adKeyPrimary ' have also tried - adKeyUnique
tbl.Keys.Append k, adKeyPrimary, "tblID"

Set cat = Nothing

End Function

----------------------------

Thanks a lot,
Oren
Nov 13 '05 #1
1 6356
A solution has been found - for all curious ones:

The ADOX catalog view-linking code was used. After the link has been
established, a unique index is added in the following manner:

DoCmd.RunSQL "CREATE UNIQUE INDEX vw1Index ON vwName(viewID)"

Oren
or**@sgdblaw.com (Oren) wrote in message news:<2f**************************@posting.google. com>...
Hi,

I've encountered difficulties in maintaining the primary key of a SQL
Server view linked dynamically in VBA to an Access database. If I use
the transferDatabase function, then the user is prompted to choose the
unique identifyer. If I create the link via the ADOX catalog, then the
key is lost and the data isn't updatable. The goal is to create a
dynamically linked updatable view without prompting the user.

Any suggestions?

By the way, here is the code I've used:
----------------------------------------

Public Function viewLinkTest()

Dim sConn As String
Dim cnn As New ADODB.Connection

cnn.Open "DSN=DSN_Name"
sConn = "ODBC;Driver={SQL
Server};Server=serverName;DATABASE=SQLdbName"

DoCmd.TransferDatabase acLink, "ODBC Database", _
sConn, acTable, vwName, linkedTableName

cnn.Close

End Function
-----------------------------------------

Public Function adoxLinker()

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim strLinkName, strTableName, sConn As String

sConn = "ODBC;Driver={SQL
Server};Server=serverName;DATABASE=SQLdbName"
strLinkName = "viewName"
strTableName = "localName"

On Error Resume Next
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables(strLinkName)
If Err = 0 Then
cat.Tables.Delete (strLinkName)
Else
Err = 0
End If

tbl.Name = strLinkName
Set tbl.ParentCatalog = cat

tbl.Properties("Jet OLEDB:Create Link") = True
tbl.Properties("Jet OLEDB:Link Provider String") = _
"ODBC; DSN = " & sConn
tbl.Properties("Jet OLEDB:remote Table Name") = strTableName
cat.Tables.Append tbl

Dim k As New Key

'''' Tried to create a unique key, but didn't manage to do so
' k.Columns = "tblID"
' k.Name = "tblID"
' k.Type = adKeyPrimary ' have also tried - adKeyUnique
tbl.Keys.Append k, adKeyPrimary, "tblID"

Set cat = Nothing

End Function

----------------------------

Thanks a lot,
Oren

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marcus | last post by:
I have a database containing my own tables and data and I wanted to be able to query this against an accountancy program which has an ODBC driver. This was never a problem with MS Access and Jet...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
9
by: Neil | last post by:
I've been discussing here a SQL 7 view which scrolls slowly when linked to an Access 2000 MDB. After trying various things, I've distilled it down to the following: when the linked view has a...
2
by: Amanda | last post by:
From a guy in Microsoft newsgroups: | In *comp.databases.ibm-db2* there are always IBM guys | from the Toronto labs on line.Post with the | -for the love of god please help- | line...
14
by: diskoduro | last post by:
Hi!! Years ago I built a database to control the production of a little factory. The users wanted to work in a Windows Net workgroup so I created an mdb with all the tables and data an after...
3
by: J. Thompson | last post by:
I have an Access application linked to a SQL Server 2000 database using ODBC. Call this database/server pair DB1 Part of the app needs to link to another local 2000 server to get data from...
5
by: anita | last post by:
I am a creating a database(db) with tables, forms, reports and queries in it. I used the Database splitter to split the database, it created a backend database with just the tables in it and I am...
8
by: Paul Hunter | last post by:
I am new to databases and thus to Access. I have a situation where I am trying to figure out how to key some tables I am working with. Consider that I have a database of my own records which are...
7
by: scoots987 | last post by:
Does anyone have a suggestion to do this? I have a table in SQL Server that has it's primary key as Bigint. When viewing directly with ODBC all the fields and rows show "#Deleted". I've tried to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.