Reproducing RunMacro action in code

Mike375

Registered User.
Local time
Today, 09:15
Joined
Aug 28, 2008
Messages
2,548
I have several of these that I would like to convert to code and because you you can't hide macro in the MDE file.

The actions being carried out by the macros are simple things...SetValue, GoToRecord, gotoControl, copy, paste.

All these macro/runmacros that I use typically run down a record set and then stop when the condition is met...or I sould say when the condition evaluates to false.

Some of them use Repeat Count and for that it will be =[Forms]![FormName]![TextboxName]

Using the Access conversion does not work as that still needs the macro.

I imagine it would be some way to repeat Call and the function that is run is simply the macro actions (in VBA) used in the macro that is run by RunMacro.

Thanks for any help. or clues/guidance
 
I think you need to tackle each of these separately. For instance the setvalue macro action (as far as I know) has no comparable vba command. The vba method setting the value of something depends on what it is you're trying to set.
 
To see what you can / cannot do with macro conversion select a macro then choose convert macros to visual basic from the Tools > Macros menu.

This will convert your macro to code which you can place inside your form or module

David
 
Ken,

SetValue is like

Forms!LetterStoreRecord!Name = Forms![MasterForm]![CLSurname]

The left hand side is the Item and the right is the Expression

As far as I am aware all macro actions can be reproduced in code....well certainly each invidual action.

If the Setvalue does a calculation then

[abc]
[abc]+1

in code will be

.abc = .abc + 1
 
To see what you can / cannot do with macro conversion select a macro then choose convert macros to visual basic from the Tools > Macros menu.

This will convert your macro to code which you can place inside your form or module

David

It is the RunMacro that is the problem because it still needs the macro.

If I put the macro actions as code into a module and then could Call with the same repeat action that would do the trick
 
Ken,

SetValue is like

Forms!LetterStoreRecord!Name = Forms![MasterForm]![CLSurname]

The left hand side is the Item and the right is the Expression

As far as I am aware all macro actions can be reproduced in code....well certainly each invidual action.

If the Setvalue does a calculation then

[abc]
[abc]+1

in code will be

.abc = .abc + 1

I'm not sure if you're still asking a question or what - ? If you are running a macro from a button click event then you have to break each line in the macro down into code that has to run in a top down manner just like in the macro...
 
It is not the conversion of the macro actions that is the problem BUT repeating the run and having it stop on meeting a condition.

But I think I might have a way. Just thought of it now:D

I make the macro that has the RunMacro action and the macro that is run by the RunMacro has RunCode as its action line and the code would be VBA versions of the macro actions in a module.

In a MDE you would still see the macro that has RunMacro action (but so what:D) and the macro that was being run would only have RunCode for the action line.....and that would be hidden in the module.

But that would be a work around. I there any way to get Call to repeat caling a fucntion until a condition is met and/or to run for a specified number of times
 
I make the macro that has the RunMacro action and the macro that is run by the RunMacro has RunCode as its action line and the code would be VBA versions of the macro actions in a module.

Why not just run the code that the runcode is calling instead of going through a stupid macro?

But that would be a work around. I there any way to get Call to repeat caling a fucntion until a condition is met and/or to run for a specified number of times

Uh... Yeah. A loop/until or a for/next :)
 
That did not work

DoCmd.RunMacro "Macro21", , "[kplus] Is Not Null"

The condition did not stop it running

This the code I put behind a label (from Access macro conversion)

DoCmd.Echo True, ""
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , "", acFirst
DoCmd.GoToControl "k"
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , "", acNext
DoCmd.RunCommand acCmdPaste
DoCmd.RunMacro "Macro21", , "[kplus] Is Not Null"
DoCmd.GoToRecord , "", acFirst

And this is the code I put in a module (again from Access conversion) and the Macro21 above just had RunCode action. It did what it had to do but would not stop.

With CodeContextObject
DoCmd.Echo True, ""
DoCmd.RunCommand acCmdSaveRecord
.k = .k + 0.25
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToControl "k"
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , "", acNext
DoCmd.RunCommand acCmdPaste
End With
 
I'm out of here Mike. For every suggestion offered you come up with a counter reason why it won't work. There is so much macro crap in your db that you can't dig your way out. I can't understand how you can follow all of this macro junk you have running and not be able to understand the relative simplicity of VBA... And all of this macro stuff is giving me a headache... :p
 
I'm out of here Mike. For every suggestion offered you come up with a counter reason why it won't work. There is so much macro crap in your db that you can't dig your way out. I can't understand how you can follow all of this macro junk you have running and not be able to understand the relative simplicity of VBA... And all of this macro stuff is giving me a headache... :p

Did you get out of bed the wrong way or perhaps the Political forum is wearing you down:D
 
Did you get out of bed the wrong way or perhaps the Political forum is wearing you down:D

Sorry. Actually I just don't use macros much and they fuzz up my brain. And as good as the bed felt this morning there is no GOOD way to get out of it :p
 
Sorry. Actually I just don't use macros much and they fuzz up my brain. And as good as the bed felt this morning there is no GOOD way to get out of it :p

You don't need to know about macros.

Jsut show me how to call a function a number of times as in

1) A specified number of times
2) A number of times equal to the value in a textbox
3) Until a condition is met.
 
You don't need to know about macros.

Jsut show me how to call a function a number of times as in

1) A specified number of times
2) A number of times equal to the value in a textbox
3) Until a condition is met.


Ok. Give me a minute or two...
 
To early in the morning for me, nearly 2am:D with cross feeding macros and whatever

I put a function in a module called abc()

How do get

Call abc

to repeat.

abc would be the code version of the macro that is run by Runmacro...thus no macros

Again

1) A specified number of times
2) A number of times equal to the value in a textbox
3) Until a condition is met. The condition would be usually the end of the records or a value in a record suc as > or <
 

Give me a couple of tips how do do that.

Do still use Call

Call Until

It is 2am here so will have a go tomorrow. I will change a few of the macros that are fun to a function.

But I still don't understand why this did not work

DoCmd.RunMacro "Macro21", , "[kplus] Is Not Null"

Macro21 had RunCode action (converted from macro). It wizzed down the record set doing what it had to do but the condition did not stop it.
 
loads of ways to manage loops - heres 3 ideas - you need to set appropriate control variables

1) fixed number of steps
for x=1 to 50
call your macro
'be careful whether you manipulate the value of x in your macro code
next x

2) while a condition is true

while x=false
run your macro
if certainsomething then x=true 'forces the loop to finish
wend

3) or jump out of the loop

while true (ie repeat forever)
run your macro
if certainsomething then goto label1
wend

label1:



--------
i tend to use while wend rather than do loop

i use while rather than repeat, as repeat does sonething at least once, while while may not do it at all.
 

Users who are viewing this thread

Back
Top Bottom