473,978 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 transferDatabas e 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.Connectio n

cnn.Open "DSN=DSN_Na me"
sConn = "ODBC;Driver={S QL
Server};Server= serverName;DATA BASE=SQLdbName"

DoCmd.TransferD atabase 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={S QL
Server};Server= serverName;DATA BASE=SQLdbName"
strLinkName = "viewName"
strTableName = "localName"

On Error Resume Next
cat.ActiveConne ction = CurrentProject. Connection
Set tbl = cat.Tables(strL inkName)
If Err = 0 Then
cat.Tables.Dele te (strLinkName)
Else
Err = 0
End If

tbl.Name = strLinkName
Set tbl.ParentCatal og = 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.Appe nd 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 6391
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.co m (Oren) wrote in message news:<2f******* *************** ****@posting.go ogle.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 transferDatabas e 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.Connectio n

cnn.Open "DSN=DSN_Na me"
sConn = "ODBC;Driver={S QL
Server};Server= serverName;DATA BASE=SQLdbName"

DoCmd.TransferD atabase 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={S QL
Server};Server= serverName;DATA BASE=SQLdbName"
strLinkName = "viewName"
strTableName = "localName"

On Error Resume Next
cat.ActiveConne ction = CurrentProject. Connection
Set tbl = cat.Tables(strL inkName)
If Err = 0 Then
cat.Tables.Dele te (strLinkName)
Else
Err = 0
End If

tbl.Name = strLinkName
Set tbl.ParentCatal og = 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.Appe nd 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
39182
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 but I hit Jet's limitations and have moved to SQL. Creating my own SQL database was no problem, but I was unsure of the best way to be able to be able to have my SQL tables and my accountancy software tables appearing in the same Access front end....
6
6808
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 the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
9
2403
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 virtual primary key, it is slow; when there is no virtual primary key, it scrolls quickly. Looking at Profiler, I see that when there is no virtual primary key, Access sends a simple select command to SQL Server. However, when there is a virtual...
2
17780
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 and I'm sure you'll get their attention. | Their usually very good:) So here's my transplanted post ==========================================
14
2985
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 that every user had his own mde linked to the main mdb. Year by year, progressively the number of records has been growing and the speed of the application has decreased strongly, because of the grrrreat number of records stored.
3
2006
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 another application database. Call it DB2 I have made a view in DB1 that brings in the data from DB2. I then link the view to the Access app. I have created a linked server login between the two DBs (call it appuser) so calls to the view can get...
5
1254
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 happy about it. But the front end db contains all of tables and forms, reports and queries, which ofcourse I am not happy about. I want the front end to contain everything except for tables in it. Is it possible to do this ? Also can i have the...
8
31576
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 invoices I work on. These invoices are from four companies with their own invoice numbers. So, I cannot key by invoice number because there is a likelihood of invoice numbers duplicated by different companies. The records in this table of joined...
7
8591
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 create a view in SQL Server and that helps, except that I can't edit the data in Access. At this point I can't change the data type on the SQL Server table. There are too many other apps that access this table to change. TIA for any help.
0
10359
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10178
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11433
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8466
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5163
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.