Can somebody provide me with a working example of using the AfterRefresh event of a QueryTable, or a link to something more intelligible than what MS deigns to provide in the Help file? Thanks in advance!
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
AfterRefresh event of a QueryTable (XP)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » AfterRefresh event of a QueryTable (XP)
- This topic has 8 replies, 2 voices, and was last updated 22 years, 6 months ago.
AuthorTopicWSShane Sargent
AskWoody LoungerSeptember 20, 2002 at 7:37 pm #376836Viewing 0 reply threadsAuthorReplies-
WSsdckapr
AskWoody Lounger -
WSShane Sargent
AskWoody LoungerSeptember 23, 2002 at 1:02 pm #619058Sure. I have a worksheet with two seperate QueryTables. After both have refreshed, running queries against an Access mdb, I’d like to compare two cells, one from each query table. My code, as it stands in a single Sub, calls the ActiveWorkbook.RefreshAll method and then starts to compare the cells. The problem is that the comparison runs well before the RefreshAll finishes and so yields erroneous results.
So, the AfterRefresh event springs to mind as a good event to trap and use to compare the cells. However, the MS team is as helpful as ever in the Help file and I’m having a bit of trouble following the example they give on how to use the AfterRefresh event of a QueryTable.
-
WSsdckapr
AskWoody LoungerSeptember 23, 2002 at 2:32 pm #619076Instead of having 1 routine: use 2 routines:
Have one routine before the refresh and this starts the “refreshall”
Have another routine, which is the task after it is refreshed. The 2nd routine is called by the “afterrefresh” event.
Routine 1 runs and calls for the refresh and this routine ends!
After the refresh is done, the afterrefresh event is triggered and this calls the 2nd routine (to compare)
the 2nd routine runs and finishes.Steve
-
WSShane Sargent
AskWoody LoungerSeptember 23, 2002 at 2:38 pm #619081 -
WSsdckapr
AskWoody LoungerSeptember 23, 2002 at 3:19 pm #619091Assume you have: 2 subs (Mod-Before and Mod-After) and 2 queryTables (named querytable1 and querytable2)
This runs mod-before which refreshes QT1. After QT1 is refreshed, it refreshes QT2. After QT2 is refreshed, it calls mod-after.I thought about using refreshall, but wanted to be sure BOTH were refreshed before calling mod-after so had them run in series.
Steve
Sub Mod-before()
‘this does all you want BEFORE refresh
‘blah
‘blah
Querytable1.refresh
end subSub Mod-After()
‘this does all you want AFTER refresh
‘blah
‘blah
end subPrivate Sub QueryTable1_AfterRefresh(Success As Boolean)
querytable2.refresh
End SubPrivate Sub QueryTable2_AfterRefresh(Success As Boolean)
mod-after
End Sub -
WSShane Sargent
AskWoody LoungerSeptember 23, 2002 at 5:04 pm #619157If you can get that to work, Steve, you’re a better man than I. The below code doesn’t fire the AfterRefresh event for the QueryTable named LastRunDate.
Private Sub CommandButton1_Click() Sheets("Detail").QueryTables("LastRunDate").Refresh BackgroundQuery:=False End Sub Private Sub LastRunDate_AfterRefresh(Success As Boolean) MsgBox "Oh...I updated!" End Sub
All of Microsoft’s literature suggests that you first must code a seperate class module to declare a QueryTable object, then dance the Hokey-Pokey to get the nasty @#$!% to work. Has anybody, anywhere in the history of clever developers actually used the AfterRefresh event of a QueryTable? I’d trade a multitude of refreshments to see one working example pulling data from the Northwind mdb…
-
WSsdckapr
AskWoody LoungerSeptember 23, 2002 at 11:04 pm #619328I apologize. It was more complicated. I couldn’t test it at work since I have no drivers to import data and I don’t have the “authority” to add new ones: Only administrators can, so I had to test it at home and I understand your frustration.
In VB (alt-f11)
Insert Class Module
Name it via properties – (F4) “clsQry” (no quotes)
Add this code to the class moduleOption Explicit Public WithEvents xlQry As QueryTable Private Sub xlQry_AfterRefresh(ByVal Success As Boolean) MsgBox ("This is after refresh") End Sub
In a normal module enter this code:
Option Explicit Dim x As New clsQry Sub Tester() Set x.xlQry = ActiveSheet.QueryTables(1) x.xlQry.Refresh End Sub
Run “Tester” macro with the “querytable on the active sheet and it will refresh the query and give the test message from the afterrefresh event.
Steve
-
WSShane Sargent
AskWoody LoungerSeptember 25, 2002 at 1:43 pm #619912
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Does anyone know how can we convert OST to Office 365? (Awaiting moderation)
by
Sanchit Tandon
1 hour, 34 minutes ago -
Installing Feature Update Windows 11 24H2
by
geekdom
15 hours, 19 minutes ago -
Windows 11 Insider Preview build 27823 released to Canary
by
joep517
15 hours, 43 minutes ago -
Windows 11 Hotpatch
by
Hackmuss
10 hours, 35 minutes ago -
System Guard service error still won’t be fixed
by
Susan Bradley
16 hours, 22 minutes ago -
Operation ForumTroll: APT attack with Google Chrome zero-day exploit chain
by
Alex5723
10 hours, 33 minutes ago -
Troy Hunt of HaveIBeenPwned Phished
by
Lars220
7 hours, 33 minutes ago -
Microsoft Windows security auditing Code 5061
by
mpw
1 day, 4 hours ago -
Can’t display images in incoming Outlook 365 emails
by
WScopwriter
12 hours, 30 minutes ago -
Windows 11 Insider Preview Build 26200.5510 early builds of 25H2
by
Alex5723
13 hours, 58 minutes ago -
0Patch : Micropatches released for SCF File NTLM Hash Disclosure Vulnerability
by
Alex5723
13 hours, 28 minutes ago -
Select multiple emails and they all open up!
by
CeeJay
2 days, 6 hours ago -
How to remove an update preview
by
Gunny
8 hours, 52 minutes ago -
Third party add ins reminder
by
Susan Bradley
4 hours, 27 minutes ago -
OTF, which backs Tor, Let’s Encrypt and more, sues to save its funding
by
Nibbled To Death By Ducks
1 day, 23 hours ago -
Updating Windows 10 to Windows 11: 23H2 or 24H2?
by
Still Anonymous
2 days, 10 hours ago -
How can I update “Explorer Patcher”
by
WSplanckster
2 days, 12 hours ago -
Check out the home page for Signal
by
CAS
2 days, 10 hours ago -
Windows 11 and Trial version of MS Office
by
Tex265
2 days, 9 hours ago -
Windows 11 Insider Preview build 26120.3585 (24H2) released to BETA
by
joep517
2 days, 16 hours ago -
Windows 11 Insider Preview build 26200.5510 released to DEV
by
joep517
2 days, 16 hours ago -
Windows 11 Insider Preview Build 26100.3624 (24H2) released to Release Preview
by
joep517
2 days, 16 hours ago -
Limits on User Names
by
CWBillow
2 days, 13 hours ago -
MS-DEFCON 4: Mixed bag for March
by
Susan Bradley
13 hours, 33 minutes ago -
Non Apple Keyboards
by
pmcjr6142
14 hours, 49 minutes ago -
How to delete your 23andMe data – The Verge
by
AJNorth
2 days, 11 hours ago -
7 common myths about Windows 11 (Microsoft AD)
by
EyesOnWindows
2 days, 9 hours ago -
Error updating to Win11 0x8024a205
by
bmeacham
8 hours, 52 minutes ago -
default apps
by
chasfinn
1 day, 16 hours ago -
Will MS Works 4 work in MS Win 11?
by
MileHighFlyer
8 hours, 38 minutes ago
Recent blog posts
- System Guard service error still won’t be fixed
- Third party add ins reminder
- MS-DEFCON 4: Mixed bag for March
- Classic and Extended Control Panel — no need to say goodbye
- Things you can do in 2025 that you couldn’t do in 2024
- Revisiting Windows 11’s File Explorer
- Planning ahead for migration
- Woody Leonhard (1951–2025)
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.