By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Call VB Functions from Query Design Grid

P: n/a
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 30 Sep 2004 03:08:40 -0700, fi*@ifs.inchcape.co.uk (Tim ffitch)
wrote:

You may be confused about the two kinds of DLLs there are:
1: Classic DLLs, including Windows API and DLLs written typically in C
or C++. They can be called like you indicated. These CANNOT be written
using VB.
2: ActiveX DLLs: the opposite of (1). Are registered using
regsvr32.exe, and can then be instantiated (CreateObject) and its
methods called (myobject.mymethod).

-Tom.

Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch


Nov 13 '05 #2

P: n/a
On 30 Sep 2004 03:08:40 -0700, fi*@ifs.inchcape.co.uk (Tim ffitch)
wrote:
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch


Hi
here is something I copied from Google (naughty but the url is just
too complicated) which spells things out a bit. To use in a query I
guess you would have to write a wrapper function (or can SQL contain
method calls - I've never tried)
David
Search Result 2
From: Greg Ellison [MS] (gr***@online.microsoft.com)
Subject: RE: Calling proceedure in external DLL
View: Complete Thread (3 articles)
Original Format
Newsgroups: microsoft.public.office.developer.vba
Date: 2002-06-17 08:48:27 PST
Hello Michael,

Any dll that you create in Visual Basic 6.0 is a COM (e.g. ActiveX)
dll.
When you create the ActiveX dll project in VB, you were provided by
default
a Class module. By default it is Class1. You need to put your
procedures in
that class module in order to call them from your template. Also, what
was
the name of the Project via the Project | Properties menu in VB6?
Both the
Project name, and the name of the class module, are important because
together they make up the ProgID. Suppose I create a VB6 ActiveX DLL
project and I change the Project name to: MyCoolProject. Then, I
changed
the name of the Class1 module to : MyCoolClass. Suppose I have a
Public
method of the class as follows:

Public MyCoolMethod (ByVal arg1 as String, ByVal arg2 as Long)
'my code for MyCoolMethod
End Sub

Now from VBA, I use Tools | References to reference the MyCoolProject
dll.
Here is how you can call the MyCoolMethod from VBA:

Dim oCool as MyCoolProject.MyCoolClass
Set oCool = New MyCoolProject.MyCoolClass
oCool.MyCoolMethod "some string", 1
Set oCool = Nothing 'release the object from memory

You can move the 'Dim oCool' statement to the module level if you want
to
use it multiple times. Then, move the 'Set oCool' to the open event of
the
document (or some other place so it is called only once).

There is an alternative for the above you can explore: When designing
your
class module in VB6 for your ActiveX dll, you will see a property of
the
Class module called 'Instancing' that you can set to 'GlobalMultiUse'
to
allow you to call the methods in the class without having to
instantiate
the object using the New keyword. See the Instancing property in VB6
online help for more information.
Best regards,
Greg Ellison
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 13 '05 #3

P: n/a
.... use Power Basic or True Basic instead of VB. Both have
a high level of compatibility with VB, but without the
artificial restrictions...

"Tim ffitch" <fi*@ifs.inchcape.co.uk> wrote in message
news:13**************************@posting.google.c om...
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch

Nov 13 '05 #4

P: n/a
Hi

I would like to thank you all for your responses so far. However
nothing so far is going to help.

I had already set the instancing of the class to GlobalMultiUse.

In my original attempt to get this working I had set a reference to my
dll and then created a public variable of my class type. I can then
succesfully call my functions from within a code module in Access.
However if I include the functions in a query I get an error stating
that my function is not defined. It seems to me that the queries
cannot refer to user defined libraries.

This is why I then tried to use the Declare statement as you would do
with API functions. I removed the reference to my dll before trying
this as I thought the two methods might clash. What seems strange
though is that if the functions were written in another Access file
and I set a reference to that file then the functions would work.

However I have spotted one common theme. If you add a class module to
access you cannot use the class or its methods in a query either.

Any other ideas anybody?

Many thanks
Tim ffitch

fi*@ifs.inchcape.co.uk (Tim ffitch) wrote in message news:<13**************************@posting.google. com>...
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch

Nov 13 '05 #5

P: n/a
On 1 Oct 2004 04:02:29 -0700, fi*@ifs.inchcape.co.uk (Tim ffitch)
wrote:
Hi

I would like to thank you all for your responses so far. However
nothing so far is going to help.

I had already set the instancing of the class to GlobalMultiUse.

In my original attempt to get this working I had set a reference to my
dll and then created a public variable of my class type. I can then
succesfully call my functions from within a code module in Access.
However if I include the functions in a query I get an error stating
that my function is not defined. It seems to me that the queries
cannot refer to user defined libraries.

This is why I then tried to use the Declare statement as you would do
with API functions. I removed the reference to my dll before trying
this as I thought the two methods might clash. What seems strange
though is that if the functions were written in another Access file
and I set a reference to that file then the functions would work.

However I have spotted one common theme. If you add a class module to
access you cannot use the class or its methods in a query either.

Any other ideas anybody?

Many thanks
Tim ffitch


Hi
other ideas all a fair amount of work:
1. Write your DLL in C
2. Use #include to put the text of your code into each of your
applications. (Ask Microsoft how to do this)
3. Simulate 2 by using insertlines on a module.
-David

Nov 13 '05 #6

P: n/a
SQL can't call functions from classes. You can only call functions
from standard modules. You may wish to write wrapper functions in
your standard modules which call your class functions.

Active X DLL's don't have function entry points like Win DLL's.
Instead, they have a standard entry point which is used to evaluate
functions. Windows calls the standard entry point and requests
the function result. Nobody, not even C++ programmers, does OLE
programming directly: it is always handled by library functions.

(david)

"Tim ffitch" <fi*@ifs.inchcape.co.uk> wrote in message
news:13**************************@posting.google.c om...
Hi

I would like to thank you all for your responses so far. However
nothing so far is going to help.

I had already set the instancing of the class to GlobalMultiUse.

In my original attempt to get this working I had set a reference to my
dll and then created a public variable of my class type. I can then
succesfully call my functions from within a code module in Access.
However if I include the functions in a query I get an error stating
that my function is not defined. It seems to me that the queries
cannot refer to user defined libraries.

This is why I then tried to use the Declare statement as you would do
with API functions. I removed the reference to my dll before trying
this as I thought the two methods might clash. What seems strange
though is that if the functions were written in another Access file
and I set a reference to that file then the functions would work.

However I have spotted one common theme. If you add a class module to
access you cannot use the class or its methods in a query either.

Any other ideas anybody?

Many thanks
Tim ffitch

fi*@ifs.inchcape.co.uk (Tim ffitch) wrote in message

news:<13**************************@posting.google. com>...
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch

Nov 13 '05 #7

P: n/a
Hi

Thanks for your detailed reply.

I had already thought of writting wrapper functions. It seems either
this or writting a C++ win32.dll are the only answers.

I would like to go down the C++ route, but I have no experience. So
unless I can get some guidance on this, wrapper functions are my only
option.

Kind regards
Tim ffitch
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message news:<41**********************@news.syd.swiftdsl.c om.au>...
SQL can't call functions from classes. You can only call functions
from standard modules. You may wish to write wrapper functions in
your standard modules which call your class functions.

Active X DLL's don't have function entry points like Win DLL's.
Instead, they have a standard entry point which is used to evaluate
functions. Windows calls the standard entry point and requests
the function result. Nobody, not even C++ programmers, does OLE
programming directly: it is always handled by library functions.

(david)

"Tim ffitch" <fi*@ifs.inchcape.co.uk> wrote in message
news:13**************************@posting.google.c om...
Hi

I would like to thank you all for your responses so far. However
nothing so far is going to help.

I had already set the instancing of the class to GlobalMultiUse.

In my original attempt to get this working I had set a reference to my
dll and then created a public variable of my class type. I can then
succesfully call my functions from within a code module in Access.
However if I include the functions in a query I get an error stating
that my function is not defined. It seems to me that the queries
cannot refer to user defined libraries.

This is why I then tried to use the Declare statement as you would do
with API functions. I removed the reference to my dll before trying
this as I thought the two methods might clash. What seems strange
though is that if the functions were written in another Access file
and I set a reference to that file then the functions would work.

However I have spotted one common theme. If you add a class module to
access you cannot use the class or its methods in a query either.

Any other ideas anybody?

Many thanks
Tim ffitch

fi*@ifs.inchcape.co.uk (Tim ffitch) wrote in message

news:<13**************************@posting.google. com>...
Hi

I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.

The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that it cant't find a valid access point in
the dll file and then gives the name of the function I am calling.

Has anyone got any ideas how I acn get this to work?

Many thanks
Tim ffitch

Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.