How to get access UDF query into an Excel vba routine when Access is not installed on computer?
This is NOT easy.
I asked a similar question (Q_21335193) 2 years ago, and the solution was ART2KMIN. But today's question cannot be satisfied with ART2KMIN.
I also asked a similar question 2 months ago, and the solution was CreateObject("Access.Appli
cation"). But todays question cannot be satisfied with that.
And I have seen many similar questions that describe using DAO to get data from Access. But todays solution cannot be satisfied with DAO.
The client's has sbs2003 is licensed for sql server, but it has never been implemented here. Perhaps that is the solution?
----------- here is the question ------------
I have an Access application that runs on 10 computers. 6 of the computers are using the Access Minumum Run Time environment, and 4 of them have Access 2003 installed.
I want Excel to grab data from an Access query which contains a UDF. Straight DAO does not allow this, it gives
' Run time error 3085
' Undefined function 'myFunction' in expression
In another try, I got an error 429 <ActiveX component cant create object > when I tried using createobject(Access Application as suggested in
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_22108929.html.
Does anybody have suggestions for a solution that will work on the 7 CPUs without purchasing Access at approximate cost of $150 each?
Microsoft's solution is very complicated and expensive. Folks can read about it here
http://office.microsoft.com/en-us/access/HA011208861033.aspx.
The client's has sbs2003 is licensed for sql server, but it has never been implemented here. Perhaps that is a solution?
If anybody feels like experimenting with this problem, the following code can be put into Access and Excel to demonstrate the problem.
----------------- code and query definitions to put into an empty access database -----------
'myQueryUDF:
' SELECT "udf" AS Expr1, always5(0) AS Expr2, * FROM MSysAccessObjects;
'
'myQuery:
' SELECT "noudf" AS Expr1, * FROM MSysAccessObjects;
'
' Function always5(x)
' always5 = 5
' end function
'
----------------- code to put into an empty Excel workbook -----------
Sub testDao()
' step 1 works on all windows computers, but step2 cannot get queries with UDF
'
Set Db = DAO.OpenDatabase("e:\aaatm
p\deleteno
w.mdb")
Set rs = Db.OpenRecordset("SELECT * from myquery")
step1:
[a1].CopyFromRecordset rs
' the following line gives
' Run time error 3085
' Undefined function 'myFunction' in expression
step2:
Set rs = Db.OpenRecordset("SELECT * from myqueryUDF")
[a20].CopyFromRecordset rs
Set rs = Nothing
Set Db = Nothing
End Sub
Sub testCreateObject()
' step 3 can access the UDF, but only if Access is installed on the computers
Set AccApp = CreateObject("Access.Appli
cation")
AccApp.OpenCurrentDatabase
("e:\aaatmp\deletenow.mdb"
)
Set Db = AccApp.CurrentDb
Set rs = Db.OpenRecordset("myQueryU
df")
step3:
[a1].CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set Db = Nothing
With AccApp
.CloseCurrentDatabase
.Quit
End With
Set AccApp = Nothing
End Sub