Making macros for subforms

E

Eric Plante

I made a macro for a subform that opens a form and it works when I open the
subform itself but it doesn't work when I try to use it from the main form.,
I get the prompt window like if it couldn'T find the value by itself. Is
there anything I can do?
 
K

Ken Snell

Can you give us just a bit more info? What are the actions that the macro is
doing? And what are the arguments for those actions? And how do you run the
macro?
 
E

Eric Plante

I tried a click on a button in the main frame and a double click macro on
the cell itself in the subform. I like the double click method much more but
in both case, I got the same result.

The details: If FormA is the main form, FormB is the subform, FormC is the
form to be opened, ItemX is an item in a cell of FormB and KeyY is the Key
of FormC, I created the macro as [KeyY] = [Form]![FormB]![ItemX] with the
right side created by clicking, not typing.

if I open the subform FormB itself, it works fine when I double click but it
opens the prompt when I do it in FormA. ItemX is the same in both
situations.
 
K

Ken Snell

When a form is serving as the subform for another form, you cannot reference
the form directly, because it's not open as a form. It exists as part of the
other form. You therefore use a reference similar to this to get to a
control on a subform in a mainform:

Forms!MainFormName!SubformControlName!ControlName

where MainFormName is the name of the main form, SubformControlName is the
name of the subform control (on the main form) that actually holds the
subform (note that the name of this subform control may or may not be the
same name as the name of the form that is serving as the subform -- the
subform control's SourceObject), and ControlName is the name of the control
on the subform.

Therefore, the macro must be written differently for when the form is open
on its own, and for when the form is a subform.

Using VBA code gets you around this problem because you can put code in the
form B (your example) that refers to itself using the Me. object, which
avoids this problem entirely.

--
Ken Snell
<MS ACCESS MVP>

Eric Plante said:
I tried a click on a button in the main frame and a double click macro on
the cell itself in the subform. I like the double click method much more but
in both case, I got the same result.

The details: If FormA is the main form, FormB is the subform, FormC is the
form to be opened, ItemX is an item in a cell of FormB and KeyY is the Key
of FormC, I created the macro as [KeyY] = [Form]![FormB]![ItemX] with the
right side created by clicking, not typing.

if I open the subform FormB itself, it works fine when I double click but it
opens the prompt when I do it in FormA. ItemX is the same in both
situations.

Ken Snell said:
Can you give us just a bit more info? What are the actions that the
macro
is
doing? And what are the arguments for those actions? And how do you run the
macro?
--
Ken Snell
<MS ACCESS MVP>

open
the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top