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!
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 8 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
-
24H2 has suppressed my favoured spider
by
Davidhs
3 hours, 27 minutes ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
7 hours, 35 minutes ago -
MS Office 365 Home on MAC
by
MickIver
1 hour, 24 minutes ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
21 hours, 38 minutes ago -
Flash Drive Eject Error for Still In Use
by
J9438
23 hours, 11 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
1 day, 16 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
1 day, 16 hours ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
20 hours, 10 minutes ago -
Migrate off MS365 to Apple Products
by
dmt_3904
20 hours, 59 minutes ago -
Login screen icon
by
CWBillow
11 hours, 21 minutes ago -
AI coming to everything
by
Susan Bradley
6 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
2 days, 8 hours ago -
No Screen TurnOff???
by
CWBillow
2 days, 8 hours ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
2 days, 9 hours ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
2 days, 20 hours ago -
How well does your browser block trackers?
by
n0ads
2 days, 6 hours ago -
You can’t handle me
by
Susan Bradley
5 hours, 46 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
1 day, 23 hours ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
3 days, 8 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
2 days, 11 hours ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
3 days, 8 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
3 days, 8 hours ago -
Lumma malware takedown
by
EyesOnWindows
2 days, 20 hours ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
3 days, 17 hours ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
3 days, 17 hours ago -
Meet Gemini in Chrome
by
Alex5723
3 days, 21 hours ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
3 days, 21 hours ago -
Trump signs Take It Down Act
by
Alex5723
4 days, 5 hours ago -
Do you have a maintenance window?
by
Susan Bradley
2 days, 10 hours ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
3 days, 7 hours ago
Recent blog posts
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.