Link to home
Start Free TrialLog in
Avatar of SparkyP
SparkyP

asked on

Filter Combobox

I currently use a query with forms!databaselogin!UserName as criteria to filter only records applicable to the current user.

Can this filter be applied using VBA
Avatar of Peter Kiprop
Peter Kiprop
Flag of Kenya image

Yes. Please provide the access db or the table names with sample data. please also indicate where to filter the data (which form).
Avatar of mbizup
Me.combo.rowsource= "select field from table where username='" & forms!formname!textboxname &"'"
Not sure if this is what you were asking but you cannot filter a combo through vba like you can with a form or report.

There is no Filter property so you have to set the rowsource property as a whole.
Avatar of SparkyP
SparkyP

ASKER

mbizup

To the resue again!

The combo is on a subform, so where would I put your code?
It depends...

How and when do you want to filter the combo?

If you wanted to do this immediately when the main form opens, you would include it in the Open Event of the main form with your other filter statements.  You would have to adjust the code a little to point to the combo on the subform:


Me.SubformControlName.Form.ComboName.Rowsource= "select field from table where username='" & forms!databaselogin!UserName &"'"

Open in new window

Also is this subform on the databaselogin form, or on a seperate form?  If it is on databaselogin, then you dont need the full form reference as a prefix for UserName.
Avatar of SparkyP

ASKER

Me.WorksheetSub.Form.JobLookup.Rowsource= "select field from table where EngName='" & forms!databaselogin!UserName &"'"

I feel I understand most of the code except

Rowsource= "select field from table where

I assume table should be replaced with my lookup table, but what else.

Sorry.
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SparkyP

ASKER

Mbizup

How good are you!!

Thanks once again and have a good weekend
You're very welcome :-)