View Full Version : Dynamic VBA Command Creation


SteveClarkson
03-28-2007, 07:39 AM
Hello,

I am sure this must be possible, and can't believe I can't find anything on it - I must be using the wrong terminology!

In VBA I would like to use code something like this:

"Forms!" & Form.Parent.Name & ".Visible=False"

The idea being, that when you click the button this code is on, it will look up the subform parents' name, and set it's "Visible" property to FALSE.

My hope is that I can use this code in a subform which is used in several parent forms - and it will cut down on VBA code somewhat.

Any help much appreciated!

boblarson
03-28-2007, 07:40 AM
Try this:
Forms(Me.Parent).Visible = False

SteveClarkson
03-28-2007, 07:49 AM
Thanks for your speedy response.

I have just tried that, but I get Runtime error 13 - Type Mismatch :(

boblarson
03-28-2007, 07:52 AM
Sorry, that should be Me.Parent.Name

SteveClarkson
03-28-2007, 07:54 AM
Just found that one myself - thank you very much for your help, that works perfectly, using:

Forms(Me.Parent.Name).Visible = False


Thanks! :D