Subform with Macro

A

Asif

I have a form (frm_BinDetails), within this form I have a subform
(frm_Cable). frm_Cable has a listbox (List23) which when the user
clicks on an entry the contents of the first column of that listbox
are displayed in a textbox (txt_ProcessID). The on click event of the
listbox runs a macro with the following code

Action = SetValue

Item = [Forms]![frm_Cable]![txt_ProcessID]

Expression = [Forms]![frm_Cable]![List23]

When I run the form frm_Cable on its own the macro works correctly but
when I try and run from frm_BinDetails then whenever I click on an
entry an error message appears saying that Access can't find the form
'frm_Cables' and then it displays my macro.

Any suggetions would be appreciated as to what I'm doing wrong (I've
already checked spellings and there all correct)

Thanks
 
L

Larry Linson

I haven't done macros in years, except for AutoKeys, but it's clear that
your problem is in the reference to the text box.

A Form embedded in a subform is not "Open" and, thus, not in the Forms
Collection -- it is the Form property of the Subform Control. But it's not
clear to me whether "frm_Cable" is the name of your Subform Control or the
Form embedded in that SubformControl. The proper reference would be:

Forms!frm_BinDetails!<nameofsubformcontrol>.Form!<nameofcontrol>

There isn't an Access Object called a "Subform" though we often use that
verbal shortcut to talk about either the "Subform Control" or "Form embedded
in a Subform Control" -- and, perhaps, that's why it can be confusing.

Larry Linson
Microsoft Access MVP
 
J

John W. Vinson

I have a form (frm_BinDetails), within this form I have a subform
(frm_Cable). frm_Cable has a listbox (List23) which when the user
clicks on an entry the contents of the first column of that listbox
are displayed in a textbox (txt_ProcessID). The on click event of the
listbox runs a macro with the following code

Action = SetValue

Item = [Forms]![frm_Cable]![txt_ProcessID]

Expression = [Forms]![frm_Cable]![List23]

When I run the form frm_Cable on its own the macro works correctly but
when I try and run from frm_BinDetails then whenever I click on an
entry an error message appears saying that Access can't find the form
'frm_Cables' and then it displays my macro.

If frm_Cable is being used as a Subform, it is *not* open in its own right,
and is not part of the Forms collection. You need to navigate to it via the
mainform:

[Forms]![frm_BinDetails]![frm_Cable].Form![txt_ProcessID]

Note that frm_Cable here is the Name property of *the Subform control* - by
default, this will be the same as the name of the Form within that control,
but it need not be.

John W. Vinson [MVP]
 
A

Asif

Thanks guys, I've tried to made the modifications as per your
suggestions but unfortunately I'm still getting an error message

Item:- [Forms]![frm_BinDetails]![frm_Cable].[Form]![txt_ProcessID]

Expression:- [Forms]![frm_BinDetails]![frm_Cable].[Form]![List23]

The following is the error message " An error occurred while
referencing the object. You tried to run a Visual Basic procedure that
improperly references a property or method of an object."

Regards
 
J

John W. Vinson

Thanks guys, I've tried to made the modifications as per your
suggestions but unfortunately I'm still getting an error message

Item:- [Forms]![frm_BinDetails]![frm_Cable].[Form]![txt_ProcessID]

Expression:- [Forms]![frm_BinDetails]![frm_Cable].[Form]![List23]

The following is the error message " An error occurred while
referencing the object. You tried to run a Visual Basic procedure that
improperly references a property or method of an object."

Regards

I'd suggest you post in the microsoft.public.access.macros newsgroup - I
never use macros and may be wrong about the syntax. Or... make the move to VBA
code, it will certainly work there (provided frm_BinDetails is open and has a
Subform control named frm_Cable with those control names).

John W. Vinson [MVP]
 

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