×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Filter a subform from a selected value in another subform

Filter a subform from a selected value in another subform

Filter a subform from a selected value in another subform

(OP)
Hello Everyone,
I am new at using VBA but I am trying to filter a subform based on the selected value of another subform. Currently, I have it in a button "btnTestFilterPersonell" but I am noticing 2 things in particular.


Private Sub btnTestFilterPersonell_Click()
Set db = CurrentDb
Set rs = db.OpenRecordset("qryfrmLinkBuildingPersonell")

Dim SelectedValue As Long

SelectedValue = Form_frmLink.subfrmPersonellLink.Form!ID.Value

Me.Filter = "[tblPersonell.ID]=" & SelectedValue
Me.FilterOn = True
Debug.Print Me.FilterOn
Me.Requery

Debug.Print rs.Fields("tblPersonell.ID")
Debug.Print SelectedValue
Debug.Print SelectedValue&; "=" & rs.Fields(3)
Debug.Print Me.Filter

Set rs = Nothing

End Sub



1) The "Me.FilterOn" status does not change to true. It stays false even after I change the FilterOn status.
2) The Filter "[tblPersonell.ID]=" & SelectedValue is not being applied.

Below are the results that I am getting from the debug.print window


Debug.Print Me.FilterOn--False
Debug.Print rs.Fields("tblPersonell.ID")--135
Debug.Print SelectedValue--93
Debug.Print SelectedValue&; "=" & rs.Fields(3)--93 =135 (Column 3 is tblPersonell.ID)
Debug.Print Me.Filter--[tblPersonell.ID]=93

I am sure it is a simple fix but I am completely stumped and will gladly accept any help you offer.

Thanks,

RE: Filter a subform from a selected value in another subform

Looking at it, the only thing that I notice is that the Requery is not necessary... I am wondering if it is somehow clearing the filteron property.

Another approach would be to change the recordsource of the form to a SQL statement with appropriate criteria then requery it.

Sometimes when things don't work, I just go with a different methodology rather than fight it.

RE: Filter a subform from a selected value in another subform

(OP)
Thanks, lameid. I will try the .Recordsource method. Thanks for your help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close