Multiple fields in stLinkCriteria

G

Guest

On form_1, I have a subform. I want to access form_2 using data from form1
and its subform. On the subform 'double_click() I coded:

Dim stLinkCriteria As String

stLinkCriteria = "([field_a] = """ & Me![field_a] & _
""") AND ([field_b] = """ & [form1].[field_b] & """)"

DoCmd.OpenForm stDocName, , , stLinkCriteria

The result is an error diolog:

Microsoft Office Access can't find the field '|' referred to in your
expression.

field_a and field_b are the 'keys' for form2. form_1 has field_b and its
subform (Me) has field_a.

How can I code the stLinkCriteria string?

Thanks in advance.
 
S

Stuart McCall

JHC said:
On form_1, I have a subform. I want to access form_2 using data from
form1
and its subform. On the subform 'double_click() I coded:

Dim stLinkCriteria As String

stLinkCriteria = "([field_a] = """ & Me![field_a] & _
""") AND ([field_b] = """ & [form1].[field_b] & """)"

DoCmd.OpenForm stDocName, , , stLinkCriteria

The result is an error diolog:

Microsoft Office Access can't find the field '|' referred to in your
expression.

field_a and field_b are the 'keys' for form2. form_1 has field_b and its
subform (Me) has field_a.

How can I code the stLinkCriteria string?

Thanks in advance.

Replace this:

[form1].[field_b]

with this:

Me.Parent.Form![field_b]
 
G

Guest

Thanks Stuart. That got past the initial error message.

stLinkCriteria = "([field_a] = """ & Me![field_a] & _
""") AND ([field_b] = """ & Me.Parent.Form![field_b] & """)"

However, now Access is prompting for input of field_b. It's like the
expression is not being honored. field_b should be =
Me.Parent.Form![field_b].

I added a watch for Me.Parent.Form![field_b] and it shows the proper value.

Do I have the syntax wrong for [field_b] in a LinkCriteria statement?





Stuart McCall said:
JHC said:
On form_1, I have a subform. I want to access form_2 using data from
form1
and its subform. On the subform 'double_click() I coded:

Dim stLinkCriteria As String

stLinkCriteria = "([field_a] = """ & Me![field_a] & _
""") AND ([field_b] = """ & [form1].[field_b] & """)"

DoCmd.OpenForm stDocName, , , stLinkCriteria

The result is an error diolog:

Microsoft Office Access can't find the field '|' referred to in your
expression.

field_a and field_b are the 'keys' for form2. form_1 has field_b and its
subform (Me) has field_a.

How can I code the stLinkCriteria string?

Thanks in advance.

Replace this:

[form1].[field_b]

with this:

Me.Parent.Form![field_b]
 
J

J_Goddard via AccessMonster.com

Hi -

Is [field_b] on form2, or a field in the RecordSource for Form2? If not, it
needs to be, because [Field_b] in the link criteria refers to [field_b] in
the sub-forms record source.

HTH

John

Thanks Stuart. That got past the initial error message.

stLinkCriteria = "([field_a] = """ & Me![field_a] & _
""") AND ([field_b] = """ & Me.Parent.Form![field_b] & """)"

However, now Access is prompting for input of field_b. It's like the
expression is not being honored. field_b should be =
Me.Parent.Form![field_b].

I added a watch for Me.Parent.Form![field_b] and it shows the proper value.

Do I have the syntax wrong for [field_b] in a LinkCriteria statement?
[quoted text clipped - 26 lines]
Me.Parent.Form![field_b]
 

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