On-Click Macro in a Subform

T

Terri

I have a continuous form that has an on-click macro associated with one of
the fields in the form. The macro opens another form based on the data in
the field associated with the record. This works fine when the original form
is on its own. If I make the form a subform in another form, the on-click
macro seems unable to pass the parameters in the Where Condition of the macro.

Is there a means of getting this to work when the macro is associated with a
field/record in a subform?

Terri
 
A

Allen Browne

Presumably the macro performs the OpenForm action, with a WhereCondition
something like this:
[SomeField] = [Forms].[Form1].[Text99]

If so, the problem is that subforms are not open in their own right. Hence
this form is not part of the Forms collection, and so the expression does
not work.

You could solve this by using an event procedure (code) instead of a macro.
The code would be like this:
Dim strWhere As String
strWhere = "[SomeField] = " & Me.[Text99]
DoCmd.OpenForm "Form2", WhereCondition:=strWhere

If SomeField is a Text field (not a number field), you need extra quotes:
strWhere = "[SomeField] = """ & Me.[Text99] & """"
Explanation:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html
 

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