VBA: Run-Time Error 3085 Using DAOID: Q180810
|
When you use Data Access Objects (DAO) in a Microsoft Office program to open a Microsoft Access query, you receive the following error message:
Run-time error '3085':
Undefined function <function name> in expression.
You are using DAO to open a query in Microsoft Access that contains a user- defined function.
You can only refer to Microsoft Jet objects that are only dependent on other Microsoft Jet objects when using DAO in other Microsoft Office programs. The following steps demonstrate this problem by creating a query in Microsoft Access that calls a user-defined function and then attempting to open a recordset on that query using DAO in Microsoft Excel.
Function IsInternational(strCountry As String) As String
If strCountry = "USA" Then
IsInternational = "Local"
Else
IsInternational = "Intl"
End If
End Function
Query: qryExcelTest
--------------------------------------
Type: Select Query
Field: CompanyName
Table: Customers
Field: Country
Table: Customers
Field: Expr1: IsInternational([Country])
Sub xlTest()
Dim db As Database, rs1 As Recordset
Dim qry As QueryDef
Set db = Workspaces(0).OpenDatabase _
("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb")
' Replace the above path with the correct path to the
' sample Northwind.mdb database on your computer.
Set qry = db.QueryDefs("qryExcelTest")
Set rs1 = qry.OpenRecordset
rs1.MoveLast
rs1.Close
db.Close
End Sub
Additional query words: prb
Keywords : kbcode kbprg kbdta AccCon KbVBA
Version : WINDOWS:5.0,7.0,97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: August 2, 1999