2
votes

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:

How do I call a VBA Function into a Sub Procedure

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
3

3 Answers

5
votes

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.

3
votes

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)

2
votes

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.