In MS Access SQL Server Linked Table pass through query

SumGuy

I have a query against a linked table in MS Access that uses the getdate() function of SQL Server. However, I get this error when I attempt to run the query:

Undefined function GetDate in function

How do I create a linked table that allows the use of SQL Server T-SQL syntax? I see that this is called a pass through query but I don't know how to set it up to use the connection on the linked table as a pass through query.

Currently using Access 2010. The query is:

select getdate()

If it helps, I used the following vba code that generates the table link to SQL Server:

Function LinkTable(LinkedTableAlias As String, Server As String, Database As String, SourceTableName As String, OverwriteIfExists As Boolean, Username As String, Password As String)
    'This method will also update the link if the underlying table definition has been modified.
    If (InStr(1, LinkedTableAlias, "MSys") > 0) Then
        Log "Skipping " & LinkedTableAlias
        Exit Function
    End If
    'The overwrite parameter will cause it to re-map/refresh the link for LinktedTable Alias, but only if it was already a linked table.
    ' it will not overwrite an existing query or local table with the name specified in LinkedTableAlias.

    'Links to a SQL Server table without the need to set up a DSN in the ODBC Console.
    Dim tdfLinked As DAO.TableDef

    ' Open a database to which a linked table can be appended.
    Dim dbsCurrent As Database
    Set dbsCurrent = CurrentDb()

    'Check for and deal with the scenario ofthe table alias already existing
    If TableNameInUse(LinkedTableAlias) Then
        'If InStr(dbsCurrent.TableDefs(LinkedTableAlias).Connect, "AccessBackup") Then
        '    Exit Function
        'End If

        If (Not OverwriteIfExists) Then
            Log "Can't use name '" + LinkedTableAlias + "' because it would overwrite existing table."
            Exit Function
        End If
        'delete existing table, but only if it is a linked table
        'If IsLinkedTable(LinkedTableAlias) Then
            dbsCurrent.TableDefs.Delete LinkedTableAlias
            dbsCurrent.TableDefs.Refresh
        'Else
        '    Log "Can't use name '" + LinkedTableAlias + "' because it would overwrite an existing query or local table."
        '    Exit Function
        'End If
    End If

    'Create a linked table
    Set tdfLinked = dbsCurrent.CreateTableDef(LinkedTableAlias)
    tdfLinked.SourceTableName = SourceTableName

    tdfLinked.Connect = "ODBC;DRIVER={SQL Server};SERVER=" & Server & ";DATABASE=" & Database & ";UID=" & Username & ";PWD=" & Password & ";"

    On Error Resume Next
    dbsCurrent.TableDefs.Append tdfLinked
    If (err.Number = 3626) Then 'too many indexes on source table for Access
            err.Clear
            On Error GoTo 0

            If LinkTable(LinkedTableAlias, Server, Database, "vw" & SourceTableName, OverwriteIfExists, Username, Password) Then
                Log "Can't link directly to table '" + SourceTableName + "' because it contains too many indexes for Access to handle. Linked to view '" & "vw" & SourceTableName & "' instead."
                LinkTable = True
            Else
                Log "Can't link table '" + SourceTableName + "' because it contains too many indexes for Access to handle. Create a view named '" & "vw" & SourceTableName & "' that selects all rows/columns from '" & SourceTableName & "' and try again to circumvent this."
                LinkTable = False
            End If
            Exit Function
    End If
    On Error GoTo 0

    '** Turn on error handling
  On Error GoTo ErrorHandler:
    tdfLinked.RefreshLink


    LinkTable = True

    Exit Function
ErrorHandler:
    Log "refreshlink failed for " & tdfLinked.Name
    LinkTable = True
Nick.McDermaid

I don't quite understand this statement:

How to I create a linked table that allows the use of SQL Server T-SQL syntax?

But this is how you convert an existing MS Access querydef to a pass through query:

Go to design mode in the query, press the Query menu command, then SQL Specific then Pass Through

See this for screenshots.

http://www.mssqltips.com/sqlservertip/1482/microsoft-access-pass-through-queries-to-sql-server/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Customizing the table linked to SQL Server in MS Access

From Dev

MS-access Pass-Through Query to SQL Server 2008 Adding Prefix

From Dev

MS Access, update query will not update a linked table

From Dev

Execute SQL Server Pass-Through Query From Access VBA

From Dev

MS Access Linked Tables to SQL Server

From Dev

Possible for T-SQL pass-through query in Access to include a local Access table?

From Dev

Possible for T-SQL pass-through query in Access to include a local Access table?

From Dev

Getting the table structure in ms access with SQL query?

From Dev

Getting the table structure in ms access with SQL query?

From Dev

MS Access pass-through query to Oracle VIA ODBC

From Dev

MS-Access - Setting parameters for pass-through query

From Dev

MS Access Date() Function and SQL Server Query

From Dev

MS Access Date() Function and SQL Server Query

From Dev

Create Linked Table in MS-Access DB on web server

From Dev

Create Linked Table in MS-Access DB on web server

From Dev

MS Access: read-only linked tables from SQL Server?

From Dev

Ms ACCESS and SQL: round to two decimals through query

From Dev

Convert MS Access data query into SQL Server database query

From Dev

Convert MS Access data query into SQL Server database query

From Dev

Access 97 Frontend - SQL Server 2005 Backend Linked Table Error

From Dev

Linked Table from SQL Server to Access has trailing spaces

From Dev

Create table in MS ACCESS 2010 - Using Oracle SQL query

From Dev

SQL query to transpose rows to columns in MS Access table

From Dev

MS Access SQL Server DB - Query Syntax for CAST Function

From Dev

Convert MS Access count and pivot query into SQL Server

From Dev

Create stored procedure in SQL Server from a MS Access update query

From Dev

MS Access SQL Server DB - Query Syntax for CAST Function

From Dev

Access linked server table collation

From Dev

MS Access Linked Table Not Updating New Fields

Related Related

  1. 1

    Customizing the table linked to SQL Server in MS Access

  2. 2

    MS-access Pass-Through Query to SQL Server 2008 Adding Prefix

  3. 3

    MS Access, update query will not update a linked table

  4. 4

    Execute SQL Server Pass-Through Query From Access VBA

  5. 5

    MS Access Linked Tables to SQL Server

  6. 6

    Possible for T-SQL pass-through query in Access to include a local Access table?

  7. 7

    Possible for T-SQL pass-through query in Access to include a local Access table?

  8. 8

    Getting the table structure in ms access with SQL query?

  9. 9

    Getting the table structure in ms access with SQL query?

  10. 10

    MS Access pass-through query to Oracle VIA ODBC

  11. 11

    MS-Access - Setting parameters for pass-through query

  12. 12

    MS Access Date() Function and SQL Server Query

  13. 13

    MS Access Date() Function and SQL Server Query

  14. 14

    Create Linked Table in MS-Access DB on web server

  15. 15

    Create Linked Table in MS-Access DB on web server

  16. 16

    MS Access: read-only linked tables from SQL Server?

  17. 17

    Ms ACCESS and SQL: round to two decimals through query

  18. 18

    Convert MS Access data query into SQL Server database query

  19. 19

    Convert MS Access data query into SQL Server database query

  20. 20

    Access 97 Frontend - SQL Server 2005 Backend Linked Table Error

  21. 21

    Linked Table from SQL Server to Access has trailing spaces

  22. 22

    Create table in MS ACCESS 2010 - Using Oracle SQL query

  23. 23

    SQL query to transpose rows to columns in MS Access table

  24. 24

    MS Access SQL Server DB - Query Syntax for CAST Function

  25. 25

    Convert MS Access count and pivot query into SQL Server

  26. 26

    Create stored procedure in SQL Server from a MS Access update query

  27. 27

    MS Access SQL Server DB - Query Syntax for CAST Function

  28. 28

    Access linked server table collation

  29. 29

    MS Access Linked Table Not Updating New Fields

HotTag

Archive