Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter a Query from a ComboBox selection?

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
I have a Query that sorts all records by date, then I have a Form that displays them in a better way and I have a Combo box and when you change the selection in the combo box it filters the Query...Like I can Filter it to be only records with Name = Bob or something...
Anyway it works perfectly fine, I used a Macro to call the ApplyFilter..

However my problem is I need some other things to be done when the combo is changed...so my Question is, how can I apply a filter to a Query using VIsual Basic Code, that way I wont need the macro...or can I call a Macro from Visual Basic code?

Thanks for any help
 
Not sure if this is the best way to do it, but you can run a macro from code like the following example:
Code:
DoCmd.RunMacro "Print Sales"
You can also add a filter (WHERE CLAUSE) to your opening of a recordset in code:
Code:
Dim db As Database
Dim rst As Recordset
Dim stringin As String
Dim pos As Integer
        
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from employees where empno = 12345")
I, myself don't care for macros and prefer to write the code myself. Access will let you save a Macro as VB code, not sure how good it works.

Hope that helps...
Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
Thanks I got it to work with the DoCmd.ApplyFilter
Works good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top