I'm using the .execute method from VB, to run an Update query in an Access .mdb. This query contains a (public) function as one of the 'update to' fields. VB bombs with 'Undefined function 'xxx'. How do I reference this function? Thanks,<br>
--Jim
What does the function do.<br>
I suppose you know that you could probably recreate that function in VB and leave Access out of the equation except for the (Tables) portion of Access.<br>
Also you can copy and paste the Function code from Access into VB and it will run as is. So you don't have to re-write the whole thing in VB.<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
I've tried to paste it to VB, but to no avail. The function references an Access Table field. Here is a simplified version...<br>
<br>
Query SQL: (Runs perfect in Access):<br>
Update tblTest Set Field1 = DoStuff([Field1])<br>
<br>
Module (In Access mdb)<br>
Public Function DoStuff( strIndata as string) as String<br>
' (This is, of course simplified, the real procedure CAN'T be performed Inline in the query,must be in function) <br>
DoStuff = strInData & "Some stuff I did in this function"<br>
Exit Function<br>
<br>
The mdb is, at times, used by the users via the Access Interface, so the function needs to be in available in Access as well. <br>
Thanks for any insight...<br>
--Jim
What do you mean an Acess table field.<br>
That's not a problem for VB<br>
Do you mean a textbox on a Access form, now that would be a problem.<br>
Give me the exact code that causes the problem and I'll make it work.<br>
or e-mail it to me and I send it back fixed... <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
To whomever might also have been wanting an answer to this situation<br>
I finally found it on my own after some tinkering, here it is:<br>
<br>
OLD WAY: ( .execute failed if query used a function within the Access Db)<br>
Dim db As Database, qd As QueryDef, pth As String<br>
pth = app.path<br>
Set db = DBEngine(0).OpenDatabase("pth & "\testdb.mdb"<br>
Set qd = db.QueryDefs("qryTest" 'Update query uses an Access function<br>
qd.Execute ' "Undefined function xxxx" was the error<br>
<br>
NEW WAY (works well)<br>
Dim db As Database, qd As QueryDef, pth As String, ac As Application<br>
pth = App.Path<br>
Set ac = New access.Application<br>
ac.OpenCurrentDatabase pth & "\testdb.mdb", False<br>
ac.Visible = False<br>
Set qd = ac.DBEngine(0)(0).QueryDefs("qrytest"<br>
qd.Execute<br>
MsgBox "You've updated " & qd.RecordsAffected & " records"<br>
ac.CloseCurrentDatabase<br>
Set ac = Nothing<br>
<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.