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

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
166
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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
Just take whatever code that you have in your button, and put it in the "AfterUpdate" event of your field.
 

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
166
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?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
Can you post the complete "AfterUpdate" event procedure VBA code that you tried below?
 

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
166

ADVERTISEMENT

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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,315
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,282
Messages
5,836,396
Members
430,425
Latest member
xlsee

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
Top