Importing Access Query with custom Function into Word (DAO)

J

jonny613287

Hi,

I have a HUGE database and need to stick lots of queries into lots of
different tables in my reports, often multiple queries in multiple
tables in the same document. As such, I can't use export and copying
and pasting creates hell with formatting and my templates. Hence i
have written a script which runs in word:

Click in the desired table, and selected the button from the toolbar.
The script opens access, asks the user to select the query from a
list, loads a selected query into a DAO recordset, and copies it into
the word table. Simple but very time-saving.

It works perfectly, unless there is a function in the query. If i have
a custom function (created in the Modules section of Access) in the
query, e.g. whenApplicable(fldReq), and I run the script, Word cannot
open the query. It gives the error:

"Undefined function 'whenApplicable' in expression"

I have tried the script line by line and the line that causes the
error is:

Set rst = dbs.OpenRecordSet(queryName) 'queryName is a
variable to which i assign the name of the query the user selects

The functions work perfectly when I run the query inside Access. I
know what is happening: while loading/running the access query from
Word, Word can't find the access function. I just don't know how to
fix it. I have tried putting this into a function in Word, but this
makes no sense and doesn't work. I have also tried the References, but
the access library is active. In Word, the library Microsoft Access
11.0, is active as well as Microsoft DAO 3.6 and Microsoft Forms 2.0.

Does anyone know how to sort this out? I can post the code if it
helps, but i don't think it will. All functions work perfectly from
inside access.

Any thoughts most welcome.

Regards

Jon
 
R

Russ

It might be a simple case of prepending your function calls by the parent
application name, or instance name of that application, they belong to;
thereby telling VBA whose function it should look for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top