Passing Variables between VB and a Macro, HOW?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a global variable defined TransferAmount and it is used by 2 VB
programs.
There is a macro which required this infromation to pass to a form, how do
you pass variables between macros and VB.

I have tried to access the public variable defined in the standard modeule
but i get errors.
 
Macros don't support variables. Either use VBA instead of a macro or create
a public function that returns the value of your public variable. VBA is a
better choice in the long run because macros do not provide any error
trapping capabilities and are limited in other ways as you can see. If you
convert your macro to code using the menu option, you can modify the
generated code to use a variable.
 
Hi Pat,

I was told that Macros were the only way to open and close forms from code.
If I can use VBA, I would prefer it, in there i can do the error checking.
But does the VBA coed continue to run afer you loos focus on the original
form where it was call from?

Dick
 
Hi Pat,

I was told that Macros were the only way to open and close forms from
code. If I can use VBA, I would prefer it, in there i can do the
error checking. But does the VBA coed continue to run afer you loos
focus on the original form where it was call from?

Yep. VBA routines run until they hit Exit or End except in cases where the
code includes a line to actually quit the application. Any lines after that
are not executed.
 
No, macros are not the only way to open form code, you can open forms in
VBA code too.

DoCmd.OpenForm "FormName", acNormal, , , acFormPropertySettings, acDialog

If you want the code on the original form that opened the new form to NOT
keep running until the new form is closed, you open the form as a modal
dialog using the acDialog value. Otherwise if you want the code to
continue immediately, use the acWindowNormal value.
 
I would point out that there's nothing that you can do in a Macro that
CAN't be done in VBA to begin with. I personally haven't used a Macro
since sometime back in 1997.
 
Whoever told you that was WRONG. FYI to open & close forms via VBA you
would use

DoCmd.OpenForm

DoCmd.Close

David H
 
Much as I hate to disagree with that statement, I don't believe you can do
the equivalent of the AutoKeys macro in VBA.
 
Ok I will try the VBA aooroach, it has MUCH more control than the Macro. I
did solve the original problem by cheating, though. I created a hidden
variable on the form that contains the data i need to pass and that worked,
however, when i return to the form after running the macros and a second for
the data will not refresh properly. So i used requery, and that needed to be
done 2x TO SEE THE CORRECTED INFORMATION.

I will try to call the second for directly from the VBA code and see if
that's better. The code needs to remain active so that so that information
can be passed back and forth though.

Thanks a lot guys!

If you have a ninute check out my question "Use of check box to select
entries..." under (search for rpatton). It seems that no one wants to tacke
that one!

God Bless, and Take care.

Dick
 
Back
Top