Solved

Running query from an OnChange event on form.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 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