tags:

views:

468

answers:

3

Very simple problem: I have a Public Sub (in a module) that I want to call from a button on a form. The name of the function I want to call from the module is GenerateKML.

I've read this post:

http://stackoverflow.com/questions/1072075/ms-access-03-how-do-i-call-a-vb-function-into-a-sub-procedure/1072200#1072200

And tried all of the suggested methods, none of which are working for me. There may be a problem with my code, but when I'm in Code view (editing the module) and press the 'play' button the code runs properly (a KML file is created).

If I use the second method suggested (call a subroutine in a module from a form) I get this error message:

Compile Error

Expected variable or procedure, not module

And if I use the third method (call a subroutine from a form without using an event procedure) I get this:

The expression On Click you entered as the event property...: The expression you entered has a function name that [my DB name] can't find.

So I suspect there's something wrong with how I'm calling the code I want to run.

This is how the code for my module starts:

Option Compare Database
Public Sub GenerateKML()
'
' GenerateKML Macro
' Macro recorded 26/09/2006 by simon_a
' Adapted and imported to Access by SAA
' 03 aug 2007 - v3.0 - 2007 08 06 19 24
'

    ' DECLARE VARIABLES
    Dim filename As String
    Dim docname As String
+4  A: 

Maybe you have named your code modules the same as the procedures within it. (just a thought)

i.e. the sub GenerateKML, sits in a module you have named GenerateKML. This creates a conflict & resulting error message.

Lil'Monkey
Thanks so much Lil'Monkey - that did it.
Munir Squires
+3  A: 

If you have named your module GenerateKML as well as your sub, you need to call it using:

GenerateKML.GenerateKML arguments

(or just rename one or the other, which is probably easier)

mavnn
Thanks mavnn, you were right, renaming it worked.
Munir Squires
+2  A: 

try renaming your module with a mod prefix: modGenerateKML. You don't reference the module name from forms, just the name of your public sub or function.

Beth
Thanks Beth! That did it.
Munir Squires