Solved

Running query from an OnChange event on form.

Posted on 2008-10-29
5
477 Views
Last Modified: 2013-11-28
I have a for that has a drop down box and I have a qry the looks at the name that is in the drop down box and returns data based on the choice. I now need the qry to run when that box changes. How do I run a query from the OnChange Event of a field?
0
Comment
Question by:jlcannon
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
SeanStrickland earned 500 total points
ID: 22831064
Is the query set as your form's recordsource?

You would use the After_Update event of the combo box generally, and the code would look like this:

Private Sub cboname_AfterUpdate()
Me.Recordsource.Requery
End Sub

Something similar to that.  I put Me.Recordsource because I'm not sure what exactly you're requerying.  However, any query that uses a combo box as part of it's criteria can be run this way, or executed with the DoCmd.OpenQuery function once the combo box has been updated (After_Update event).
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22831094
I am guessing from the wording of your Q that you are not a code writer.
Therefore the simplest way to do this is to build a macro that uses the Openquery action to open your named query.
Then in the OnChange event property you can select that macro from the drop down list and it will run whenever the value changes - although you will have to close the query yourself each time, before the next run.
0
 

Author Comment

by:jlcannon
ID: 22831470
ok when I do this:
Private Sub Combo6_Change()
Me.qryReport.Requery
End Sub

I get Method or data member not found error when I change the name in the first dox.
0
 

Author Comment

by:jlcannon
ID: 22831706
Private Sub Combo6_AfterUpdate()
Me.List8.Requery
End Sub

that worked. Thanks, I just misunderstood what you meant.
0
 
LVL 11

Expert Comment

by:SeanStrickland
ID: 22833431
Great!  Glad I could help. :)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now