Home Forums Microsoft Access Microsoft Access call a SQL Server User Defined Function from Access query RE: call a SQL Server User Defined Function from Access query

  • Hi,

    dbo is the schema owner, as all objects in SQL Server are owned by a schema (dbo = database owner). It's the usual syntax for every object in SQL Server, more info you find in BOL.

    Btw, the query didn't run with

    SELECT dbo.udf_GetStuff (44, 22) AS retVal

    and I don't know whats the issue.

    What I really needed was a VBA solution which works this way:

    Public Function fctRunUDF_GetStuff(ByVal inlng_arIdnr As Long _

    , ByVal lngSKey As long _

    ) As Currency

    '===

    ' calling a SQL Server UDF (User defined function) from Access VBA

    '

    '===

    Dim currDB As DAO.Database

    Dim strSQL As String

    Dim varReturn As Variant

    Const cstrODBC as string = "ODBC;DSN=hubba;Description=hubba;UID=Administrator;DATABASE=hubba;Trusted_Connection=Yes"

    Set currDB = CurrentDb()

    strSQL = "SELECT dbo.udf_GetStuff (44, 22) AS retVal"

    With currDB.CreateQueryDef("", strSQL)

    .Connect = cstrODBC

    varReturn = .OpenRecordset.Fields(0)

    End With

    fctRunUDF_GetStuff = varReturn

    currDB.Close

    Set currDB = Nothing

    and it works:-)

    --
    candide
    ________Panta rhei