We help IT Professionals succeed at work.

Filter Combobox

SparkyP
SparkyP asked
on
363 Views
Last Modified: 2012-06-21
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
Comment
Watch Question

Yes. Please provide the access db or the table names with sample data. please also indicate where to filter the data (which form).
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Me.combo.rowsource= "select field from table where username='" & forms!formname!textboxname &"'"
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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.

Author

Commented:
mbizup

To the resue again!

The combo is on a subform, so where would I put your code?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Mbizup

How good are you!!

Thanks once again and have a good weekend
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
You're very welcome :-)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.