Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Filter a sub form

Dear Experts

I am trying to apply a filter to a sub form from a list box.

The List box "PeopleList" has amongst other data a first column of [UniqueID] (which is hidden from view).

The Sub Form "BioViewer" has 4 fields in it including  [UniqueID] and all data comes from the same query as the list box.

What I am after doing is this ... when the user clicks on a person in the "PeopleList" list box, the Sub Form "Bioviewer" should filter or navigate straight to that record.

Can anybody help?
Microsoft Access

Avatar of undefined
Last Comment
Tom Crowfoot
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

1st, in the after update event of your list box (PeopleList) have:

MsgBox PeopleList.column(0)
MsgBox Vartype(PeopleList.column(0))

1st one to make sure you are getting the correct ID and the second on to find its variable type. This just a test before we move on.

brb
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

re:> filter or navigate straight to that record.

Which you want filter or navigate?

Mike
Avatar of AccountingDev
AccountingDev

This is a fairly comon task.  
1. Create form with your list box source will be "PeopleList"
2. Create query "SelectedUser" with all the fields from "BioViewer" and [UniqueID] criteria = Form.Listbox.Value
3. Create subform with field source of "SelectedUser" and relevant fields pulling data you wish to display
4. On the list box event 'After Update' perform a refresh/redraw on the subform.
Avatar of Tom Crowfoot
Tom Crowfoot
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi eghtebas,

Ran the test - the [UniqueID] is coming up correct and the MsgBox Vartype(PeopleList.column(0)) comes up with "8".

as far as Filter or navigate, i really dont mind, whatever is quicker to retunr results / is deemed better practice
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

8 means it delivers it as string whereas we need it as long (assuming it is long in your table) so we will have it as:

MsgBox Vartype(Clng(PeopleList.column(0)))

down the line.

brb
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

sorry for the delay...

In the afterupdate event ofthe list box have:


Me.sfSubformName.Form.Filter = Clng(PeopleList.column(0))
Me.sfSubformName.Form.FilterOn = True
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

When you open your main form in design view and click on the subform once, the property sheet shows the subform name (replace sfSubformName I have used here with whatever you have). Remember to click only once on the subform to see its container name.
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

This will give you by filter. After the filter you may wish to remove filter. To do so, add a button "Reset" and in its on click event add:

Me.sfSubformName.Form.FilterOn = False
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

correction....


Me.sfSubformName.Form.Filter = "UniqueID=" & Clng(PeopleList.column(0))
Me.sfSubformName.Form.FilterOn = True
Avatar of Tom Crowfoot
Tom Crowfoot
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hi,

Tried this, unfortunately I keep getting a run time error '13': type mismatch, I've tried playing around with it a bit doing things such as putting in the full field name (is with the query name in it etc) but alas no joy.  The only other thing that may make a difference is that the UniqueID's can contain spaces - not sure if that makes any difference
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

I have tested the solution before posting it. If you could isolate the portion we are working with with min. data, upload it for me to take a look at it.

Is UniqueID field Long Integer or it is text?

Mike
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Tom Crowfoot
Tom Crowfoot
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

The unique ID is text which is formed from this ... The original data comes from a linked excel spreadsheet and is formed by joining up 4 fields:  name, location, company, job title.

Technically there is the possibility of this not being unique, but with the sample data I'm using it is (I've run duplicate checks based on this).  To ensure the unique ID remains unique users will be putting the raw excel data through an access validation tool prior to submitting data.

Sorry I should have mentioned this in the original post.

Unfortunately I won't be able to upload a dataset until tomorrow when I am back in the office, but will do so first thing

Avatar of Tom Crowfoot
Tom Crowfoot
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Just got your post - will give that a go first thing - thanks for your help on this
Avatar of Tom Crowfoot
Tom Crowfoot
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thank you so much (finally also managed to login from home so was able to test it) - works a treat
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo