Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a function in the BackEnd from a macro in the FrontEnd

Status
Not open for further replies.

GregTheGeek

Programmer
Aug 11, 2004
46
US
I have a back-end MDE (BE) that holds my functions, subs, and class modules. I then have this BE MDE referenced in my front-end (FE) MDB. Everything was great... until today.

This thread gives a good idea of what I'm trying to do, but comes just short of giving the answer I need:
thread705-968486

My issue:
I wrote a function in my BE that opens a form prompting the user for the parameters needed to link a mySQL table. This all works well. Now, in the FE, I want to call this function from a macro so the user doesn't have to resort to using the immediate window. How do I reference this function from within macro designer? Everything I have tried results in an error stating the function could not be found.

I have temporarily gotten around this by creating a wrapper function in my FE that simply calls the function in the BE. However, I don't want to have to do this in *EVERY* MDB that references the BE MDE.

Thanks in advance!

gtg.jpg

GTG
 
I think that is correct. The runcode macro looks in the standard module for a function with that name unless it is in response to a user action on a form. Then it looks through the form's class module.

However, seems you could have a nicer interface than having the user go a macro. While not a custom toolbar for those backend functions, or a form to run it?
 
MajP,

Thank you for your response.

The function itself opens a form (which resides in the BE MDE), so I don't want to create yet another form just to call this function.

My users are on a technical level, so really, using a macro is just for convenience, not aesthetics.

* If I call the function from the Immediate window, it runs fine.
* If I call the function from a local wrapper function, if runs fine.
* If I call the local wrapper function from a local macro, it runs fine.
* If I call the function directly from a local macro, it breaks.



gtg.jpg

GTG
 
Yes that was what I said. Of course you can call the referenced function, and of course you can call the local function. But, as I pointed out it is a limitation of the runcode macro that only can look into the existing standard modules.

f you use the RunCode action to call a function, Access looks for the function with the name specified by the Function Name argument in the standard modules for the database. However, when this action runs in response to clicking a menu command on a form or report or in response to an event on a form or report, Access first looks for the function in the form's or report's class module and then in the standard modules. Access doesn't search the class modules that appear in the Modules area of the Navigation Pane for the function specified by the Function Name argument.
So why not add a menu choice (seems way more convenient) or a shortcut menu?
 
My apologies, I misunderstood the intent of your message. Just to be clear, you are telling me is there is really no way to do what I want by only using a macro?

Unfortunately custom toolbar/menu controls will only reference macros (at least in Access 2K/2K3). I guess I will have to create a wrapper function AND a macro in each FE MDB where I want to use my BE function. <sigh>

Thank you for your time.

gtg.jpg

GTG
 
Unfortunately custom toolbar/menu controls will only reference macros
Not sure what you are referring to but of course you can call a vba procedure from a menu item onAction property. However, I need to check if it has the same limitation in being able to find it.
 
I tested it and there is absolutely no problem creating a custom menu item that can call a referenced function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top