Query to run automatically after a value is filled in a field

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
175
Hello guys,

Is it possible when I insert a value in a form field, the form to run a query, updating some other fields of the table that is related to the form?

I want let's say to insert the word "Monday" and the query to insert to the table related to the form (and therefore appear on the form), my appointments which are already stored in another table.

I have managed to do it with a button but I would like to do it automatically when the field is filled. I have tried textbox events but with no luck...
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Just take whatever code that you have in your button, and put it in the "AfterUpdate" event of your field.
 
Upvote 0
Hi Joe,

Surprisingly, this doesn't work and I can't understand why. I have tried with the txtbox event (afterupdate) both with macro and vba but nothing happens. When I insert the value and press the button everything is working, but I can't get that automatically. .
Could it be something that may be affecting this?
 
Upvote 0
Can you post the complete "AfterUpdate" event procedure VBA code that you tried below?
 
Upvote 0
I just see that it does run the query but I have to save the record first (by moving t the next one) and I have to return and replace the value to execute it.
As I can understand there shouldn't be any way to update the fields if I haven't saved the record right?

Would it be possible to run the query when I am moving to the next record instead (probably a different event)?

Thanks
 
Upvote 0
Did you use the "AfterUpdate" event of the field or the form?
You may also need to Refresh the form at the end of your code to see the updated fields.

I am thinking for what you are doing, perhaps a Form/Subform relationship would work better.
Something like this:
Note that there are also many other videos on the same topic.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top