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, 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
-
Beijing’s unprecedented half-marathon: Humans vs. humanoids!
by
Alex5723
2 hours, 10 minutes ago -
New Phishing Campaign Targeted at Mac Users
by
Alex5723
9 minutes ago -
Backing up Google Calendar
by
CWBillow
8 hours, 38 minutes ago -
Windows 11 Insider Preview build 27818 released to Canary
by
joep517
21 hours, 15 minutes ago -
File Naming Conventions (including Folders)
by
Magic66
5 minutes ago -
Windows 11 Insider Preview Build 26100.3613 (24H2) released to Release Preview
by
joep517
1 day, 4 hours ago -
Microsoft sends emails to Windows 10 users about EOS
by
Alex5723
15 hours, 11 minutes ago -
Outlook 2024 importing Calendar and Contacts – FAILURE
by
Kathy Stevens
42 minutes ago -
Adding Microsoft Account.
by
DaveBRenn
1 day, 5 hours ago -
Windows 11 Insider Preview build 26120.3576 released to DEV and BETA
by
joep517
2 days, 5 hours ago -
Windows 11 Insider Preview Build 22635.5090 (23H2) released to BETA
by
joep517
2 days, 5 hours ago -
Windows 11 won’t boot
by
goducks25
2 days, 19 hours ago -
Choosing virtual machine product for Windows on Mac
by
peterb
1 day, 19 hours ago -
Rest in Peace
by
Roy Lasris
3 days ago -
CISA : Install Windows March 2025 Updates until April 1 or shut down PC.
by
Alex5723
2 days, 23 hours ago -
Google proposes users with incompatible Win 11 PCs to migrate to ChromeOS Flex
by
Alex5723
3 days ago -
Drivers for Epson Perfection V600 Photo – scanner
by
Bookman
2 days, 5 hours ago -
Long Time Member
by
jackpet
3 days, 3 hours ago -
Woody Leonhard (1951–2025)
by
Will Fastie
3 hours, 38 minutes ago -
What I learned from Woody Leonhard
by
B. Livingston
2 days, 20 hours ago -
Windows Settings today
by
Simon Bisson
3 days, 11 hours ago -
Mail Merge magic in Microsoft Word
by
Peter Deegan
9 hours, 39 minutes ago -
Businesses in the crosshairs
by
Susan Bradley
2 days, 1 hour ago -
Double-row taskbar?
by
CWBillow
17 hours, 10 minutes ago -
Upgrading non-supported HW to Win 11
by
RetiredGeek
1 day, 2 hours ago -
Audio locks up after 15 minutes
by
WSArthurR
1 day, 2 hours ago -
Copilot app uninstalled
by
Susan Bradley
1 day ago -
Strongbox Password Manager Sold to Applause Group – Cost Escalation Imminent
by
Paul T
4 days, 21 hours ago -
SharePoint
by
CBFPD-Chief115
3 days, 19 hours ago -
Google replacing Google Assistant with Gemini AI assistant
by
Alex5723
5 days 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.