[AccessD] Use module function in query from vb.net

Phil Jewett pjewett at bayplace.com
Mon Dec 26 16:12:23 CST 2005


I am trying to retrieve an Access query using ado.net that includes a
module function for a column (actually several columns).  The query
works fine from within Access, but when called from ado.net it fails
with the error "Undefined function 'GetMyDesc' in expression".  
 
The access query:
 
MyQuery:  "select GetMyDesc([thecode]) as MyDescription.... from
[MasterTable]"
 
The function GetMyDesc is a public function in a module:
 
Public Function GetMyDesc(ByVal ID As Long) As String
    Dim HoldID As Long
    HoldID = Nz(ID, 0)
    GetMyDesc= Nz(DLookup("CodeDesc", "CodeTable", "ID = " & HoldID),
"")
End Function
 
This is my ado.net code:
 
cmd.CommandText = "MyQuery"
cmd.CommandType = CommandType.StoredProcedure
Try
FoundDR = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch e As Exception
MsgBox("Error: " & e.Message)
End Try
 
 I have tried using a command type of both stored procedure and plain
text, with the same error resulting.
 
As for the reason for doing this in the first place, the MasterTable has
14 or so foreign keys, and rather than join 14 references to the code
lookup table, I use the function to retrieve the code descriptions.  But
being able to get to an Access module function from ado.net seems just
as necessary as getting to user functions in SQL server.
 
Phil Jewett



More information about the AccessD mailing list