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
-
Xfinity home internet
by
MrJimPhelps
1 hour, 11 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
3 hours, 28 minutes ago -
Debian 12.11 released
by
Alex5723
8 hours, 11 minutes ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
11 hours, 53 minutes ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
9 hours, 22 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
8 hours, 21 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
1 day, 4 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
19 hours, 13 minutes ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
1 day, 7 hours ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
23 hours, 44 minutes ago -
Some advice for managing my wireless internet gateway
by
LHiggins
7 hours, 17 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
8 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
1 day, 16 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 13 hours ago -
Does windows update component store “self heal”?
by
Mike Cross
1 day, 3 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
2 days, 6 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
14 hours, 52 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
3 hours, 30 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
2 days, 9 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
2 days, 9 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
1 day, 22 hours ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
2 days, 17 hours ago -
0Patch, where to begin
by
cassel23
2 days, 11 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
3 days, 7 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
2 days, 19 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
3 days, 15 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
3 days, 6 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
9 hours, 6 minutes ago -
Installer program can’t read my registry
by
Peobody
1 hour ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
3 days, 4 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.