Senin, 17 Agustus 2015

RE: [MS_AccessPros] calling function in vba

 


thanks
Sarah

---In MS_Access_Professionals@yahoogroups.com, <wrmosca@...> wrote :

Sarah

 

I can state it works for 2007 and 2010. Since 2013 (Office 365) made very few changes to Access, I'm sure it will work in those as well. Remember...VBA rarely drops functionality for built-in functions. It usually just adds to the list.

 

Regards,
Bill Mosca,
Founder, MS_Access_Professionals
That'll do IT http://thatlldoit.com
MS Access MVP
http://mvp.microsoft.com/en-us/mvp/Bill%20Mosca-35852

My Nothing-to-do-with Access blog

http://wrmosca.wordpress.com

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Friday, August 14, 2015 2:17 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] calling function in vba

 

 

 

One more thing I forgot to ask:

I am currently working in Access 2003.

Is EVAL going to work Access 2010, 2013 ?

Sarah

---In MS_Access_Professionals@yahoogroups.com, <sarahk@...> wrote :

 

John,

Eval works !!! with and without 'call' in front of it.

Are you saying it is not a good idea to use 'eval'??

Thanks

Sarah

---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Sarah-

 

Then you'll have to put something in the Button Event field that can be easily interpreted in VBA.

 

There is a function called Eval, but I'm not sure it will work for your situation.  If the field were to contain the string:

 

mm("Definition Menu")

 

.. and all of the options always call some function, then you could try:

 

Call Eval(![Button Event])

 

.. but I don't think that will work because the Call statement must be compiled into your project, and it probably can't evaluate a dynamic string.

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications 

SQL Queries for Mere Mortals 

(Paris, France)

 

 

 

On Aug 14, 2015, at 7:07 PM, sarahk@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

No, I don't always call the mm function. there are other functions as well. 

Yes, I do have the with statement.

Sarah



---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Sarah-

 

Do you always call the mm function, just with a different argument?  If so, then put the argument value in the field and just do:

 

    Call mm(![Button Event])

 

I assume you have a With statement preceding this that sets the base on which the ! operates.

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications 

SQL Queries for Mere Mortals 

(Paris, France)

 

 

 

On Aug 14, 2015, at 6:33 PM, sarahk@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

I see that I could do it this way, but then for every [button event] entry I add to the table, I would have to modify my Case /code. I was hoping there is a way todo this by storing  'mm("Definition Menu")' in the button event and then calling the procedure name from the information in the [button event] field. For example, I would like to put mm("Definition Menu") into the button event field and call the function without having to examine every case.

Is this doable?

Sarah



---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

Sarah-

 

Let me see if I understand this.

 

In the field [button event], at least for the current record, you have the text string:

 

"mopen.dm"

 

I assume other records might have a different macro name in the [button event] field.

 

When you execute that string as a macro name, it calls the macro defined in the field - and in this case, that macro runs a function called mm and passes it the parameter "Definition Menu".

 

If you want to avoid the macro, your code is going to have to examine what's in the [button event] field and then call the appropriate function.  Something like:

 

    Select Case ![button event]

        Case "mopen.dm"

            Call mm("Definition Menu")

        Case … something else

            Call ….

    End Select

 

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications 

SQL Queries for Mere Mortals 

(Paris, France)

 

 

 

On Aug 14, 2015, at 5:44 PM, sarahk@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

 

 

Maybe I did not explain well:

 

Currently I have this setup:

 

I have a macro 'mopen', the entry in the macro:

macro name 'dm' action 'run code'

function name=mm("Defintion Menu")

 

Currently I have a table with field '[button event]

![button event]=mopen.dm

 

when the button is selected , i triggers the following event:

DoCmd.RunMacro (![button event]) and then executes mm("Definition Menu") correctly.

 

I would like to eliminate the step of calling the 'mopen' macro and loading mm("Definition Menu") into the [button event] field and then running the function that is stored in [button event]. 

How do I / can I tell VBA to run the function that is store in [button event]?

 

Or do I just have to keep the 'mopen' macro to make this work.

 

Sarah



---In MS_Access_Professionals@yahoogroups.com, <duanehookom@...> wrote :

Sarah,
What is the code for the function mm()?
 
What is A?
Is rstMenu a recordset and [BUTTON EVENT] a field in that recordset?
Have you attempted to set a break point and step through your code?
Is the "{" just a typo in your email or is it in your code?
Could you share more of your code?
 
Duane Hookom, MVP
MS Access
 


To: MS_Access_Professionals@yahoogroups.com
From: MS_Access_Professionals@yahoogroups.com
Date: Thu, 13 Aug 2015 15:43:07 -0700
Subject: [MS_AccessPros] calling function in vba



i have a function 'mm'. I am trying to call this function with a variable from a table, it does not work, The exact same function works if I type the variable name directly into the statement. 


the following does not work, does not do anything. I tried with and without "()". does not make a difference
A = (rstmenu![BUTTON EVENT])
A = rstmenu![BUTTON EVENT]

The following works:
A = mm("Definition Menu")

 rstmenu!{button event] =mm("Definition Menu")

 

What am I doing wrong?

Sarah

 

 




 

 

 

__._,_.___

Posted by: sarahk@schemesoftware.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (13)

.

__,_._,___

Tidak ada komentar:

Posting Komentar