Filter on Current Record

R

REGREGL

Hello all...

I have a form (formA) witha subform (formB). The subform is set to
continuous records view. I would like to have a button within the subform
which will open another form (formC) and filter formC by the currently
selected record in formB.

Now, I would have no problem with this if formB were set to Single View. In
that case I could create a filter and use the criteria [forms]![formB]![Order
Number] to accomplish what I want. But with the form view set to Continuous
Records, the filter criteria doesn't understand which [Order Number] to use.

Thanks in advance for your help!
 
J

Jeanette Cunningham

If I have understood your request, the button uses the current ID for formB
to open formC using a filter like this:

Private Sub cmdOpen_Click()
DoCmd.OpenForm "formC", , , "[KeyID] = " & Me.txtID & "" 'number field
'DoCmd.OpenForm "formC", , , "[KeyID] = """ & Me.txtID & """"
'text field
End Sub

That code will open formC to show just the details for the currently
selected record in formB.

Jeanette Cunningham
 
R

REGREGL

What is supposed to replace the "me.txtID"? I have replaced the "formC" and
"[key ID]" fields with the relevant data. But it sticks when it gets to
Me.txtID.

Jeanette Cunningham said:
If I have understood your request, the button uses the current ID for formB
to open formC using a filter like this:

Private Sub cmdOpen_Click()
DoCmd.OpenForm "formC", , , "[KeyID] = " & Me.txtID & "" 'number field
'DoCmd.OpenForm "formC", , , "[KeyID] = """ & Me.txtID & """"
'text field
End Sub

That code will open formC to show just the details for the currently
selected record in formB.

Jeanette Cunningham


REGREGL said:
Hello all...

I have a form (formA) witha subform (formB). The subform is set to
continuous records view. I would like to have a button within the subform
which will open another form (formC) and filter formC by the currently
selected record in formB.

Now, I would have no problem with this if formB were set to Single View.
In
that case I could create a filter and use the criteria
[forms]![formB]![Order
Number] to accomplish what I want. But with the form view set to
Continuous
Records, the filter criteria doesn't understand which [Order Number] to
use.

Thanks in advance for your help!
 
J

Jeanette Cunningham

Make sure your subform has the foreign key from its recordsource as a bound
textbox on it - the field that is used in the Master child links - make sure
it is a control on the subform.

Replace ID with the name of that field
I used txt as the prefix for the name of the textbox, this is the way I do
naming.
If the linking field was called OrderID, I would call the text box
txtOrderID.
We are using txtOrderID because it is the thing that identifies which row on
the subform to filter on when opening formC.
Does this explain it?

Jeanette Cunningham

REGREGL said:
What is supposed to replace the "me.txtID"? I have replaced the "formC"
and
"[key ID]" fields with the relevant data. But it sticks when it gets to
Me.txtID.

Jeanette Cunningham said:
If I have understood your request, the button uses the current ID for
formB
to open formC using a filter like this:

Private Sub cmdOpen_Click()
DoCmd.OpenForm "formC", , , "[KeyID] = " & Me.txtID & "" 'number
field
'DoCmd.OpenForm "formC", , , "[KeyID] = """ & Me.txtID & """"
'text field
End Sub

That code will open formC to show just the details for the currently
selected record in formB.

Jeanette Cunningham


REGREGL said:
Hello all...

I have a form (formA) witha subform (formB). The subform is set to
continuous records view. I would like to have a button within the
subform
which will open another form (formC) and filter formC by the currently
selected record in formB.

Now, I would have no problem with this if formB were set to Single
View.
In
that case I could create a filter and use the criteria
[forms]![formB]![Order
Number] to accomplish what I want. But with the form view set to
Continuous
Records, the filter criteria doesn't understand which [Order Number] to
use.

Thanks in advance for your help!
 
R

REGREGL

Thank you very much Jeanette, that did the trick!!!

Jeanette Cunningham said:
Make sure your subform has the foreign key from its recordsource as a bound
textbox on it - the field that is used in the Master child links - make sure
it is a control on the subform.

Replace ID with the name of that field
I used txt as the prefix for the name of the textbox, this is the way I do
naming.
If the linking field was called OrderID, I would call the text box
txtOrderID.
We are using txtOrderID because it is the thing that identifies which row on
the subform to filter on when opening formC.
Does this explain it?

Jeanette Cunningham

REGREGL said:
What is supposed to replace the "me.txtID"? I have replaced the "formC"
and
"[key ID]" fields with the relevant data. But it sticks when it gets to
Me.txtID.

Jeanette Cunningham said:
If I have understood your request, the button uses the current ID for
formB
to open formC using a filter like this:

Private Sub cmdOpen_Click()
DoCmd.OpenForm "formC", , , "[KeyID] = " & Me.txtID & "" 'number
field
'DoCmd.OpenForm "formC", , , "[KeyID] = """ & Me.txtID & """"
'text field
End Sub

That code will open formC to show just the details for the currently
selected record in formB.

Jeanette Cunningham


Hello all...

I have a form (formA) witha subform (formB). The subform is set to
continuous records view. I would like to have a button within the
subform
which will open another form (formC) and filter formC by the currently
selected record in formB.

Now, I would have no problem with this if formB were set to Single
View.
In
that case I could create a filter and use the criteria
[forms]![formB]![Order
Number] to accomplish what I want. But with the form view set to
Continuous
Records, the filter criteria doesn't understand which [Order Number] to
use.

Thanks in advance for your help!
 

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