Showing posts with label QueryTable. Show all posts
Showing posts with label QueryTable. Show all posts

QueryTable Events

QueryTable AfterRefresh Event

This event occurs after a query is completed or canceled.


QueryTable BeforeRefresh Event

This event occurs before the query tables refreshes. This event can occur by calling the refresh method of the query table or when the workbook that contains the query table is opened.


QueryTable BeforeRefresh Event



Syntax
Private Sub QueryTable_BeforeRefresh(Cancel As Boolean)
Enter Code
End Sub

This event occurs before the query tables refreshes. This event can occur by calling the refresh method of the query table or when the workbook that contains the query table is opened.

Required Parameters
Cancel
The cancel parameter will determine if the query table is refreshed or not. If the parameter remains set to true then the query table will be refreshed. If the parameter is set to false then the query table will not refresh.

Example
Private Sub QueryTable_BeforeRefresh(Cancel As Boolean)
 a = MsgBox("Refresh Now?", vbYesNoCancel)
 If a = vbNo Then Cancel = True
 MsgBox Cancel
End Sub

Result
This example runs before the query table is refreshed.

QueryTable AfterRefresh Event



Syntax
Private Sub QueryTable_AfterRefresh(Success As Boolean)
Enter Code
End Sub

This event occurs after a query is completed or canceled.

Required Parameters
Success
The success parameter will return a value of true if the query was completed successfully. It will return a value of false if the refresh failed or was cancelled.

Example
Private Sub QueryTable_AfterRefresh(Success As Boolean)
 If Success Then
 ' Query completed successfully
 Else
 ' Query failed or was cancelled
 End If
End Sub

Result
This example uses the Success argument to determine which section of code to run.