Unselect Listbox value after requery err
Posted on 2006-05-31
Hi all - stumped good again. Single form bound to table with combox cmb_county and listbox lst_services at top to filter records.
cmb_county is unbound top-level filter that after update requeries form filtered on county selection, and also requeries lst_services to filter for that county.
lst_services is unbound listbox based on query filtered by cmb_county value. After lst_services update, form is requeried to filter based on both county and service selected. Records are in form detail, and everything works fine (choose county, all records for that county and services reload to just services for that county; choose service, only records for that service in that county show).
The only problem is that after a user has selected both a county and a service, and then chooses a different county, the services selection stays on their original selection, even though the county resets and the form shows all records for that county. So i'm trying to add code to 'unselect' the service, and it keeps crashing access (says it is generating err log but can't find).
tried changing lst_services on_update event to on_click, but still crashes when: pick county (form and lst_services update fine), pick service (form updates fine), pick new county (form updated fine but services still show old choice), pick new service (access hesitates and then crashes, doesn't even max cpu). cmb_county code to update is below.
rststring = "Select * from tSvcProviderDetail where [tCounty_ID] = " & Me.cmb_County
Debug.Print "cnty=" & rststring
Me.Form.RecordSource = rststring
For Each varI In lst_Services.ItemsSelected
lst_Services.Selected(varI) = False
the lines that crash access are the For...Next loop, regardless of where i place them - take them out everything's fine (except lst_services shows up with old selection).