Solved

Running query from an OnChange event on form.

Posted on 2008-10-29
5
501 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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