OLE DB Refresh - Comment gerer les erreurs
Bonjour,
j'essais de developper une macro se lancant a l'ouverture du workbook (load) qui va rafraichir une feuille a partir d'une data base sur un Share Point...
J'ai trouver sur le wed une routine qui fonctionne bien (voir ci-apres)...
Par contre je seche pour gerer les erreurs dans le cas ou la base de donnee n'est pas accessible... particulierement dans le cas ou excel ou une fenetre d'alerte indiquant a l'utilisateur que la DB n'est pas accessible OK/CANCEL... si l'utilisateur presse OK, alors la variable ERR vidée... impossible de savoir qu'il y a eu une erreur...
Est ce que quelqu'un a deja rencontre le probleme ou serait me guider vers une solution ?
Par avance merci
Daniel.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
On Error GoTo endE
'For stand alone utility ---------------------------------------------------
With ActiveWorkbook.Connections("owssvr[1]")
'For the Add-In utility ----------------------------------------------------
'With Workbooks(WBo).Connections("owssvr[1]")
'---------------------------------------------------------------------------
'Application.DisplayAlerts = False
Err.Clear
Select Case .Type
Case xlConnectionTypeODBC
With .ODBCConnection
.Refresh
Do While .Refreshing
DoEvents
Loop
End With
Case xlConnectionTypeOLEDB 'Our connection is OLE DB Type = 1
With .OLEDBConnection
.Refresh
Do While .Refreshing
DoEvents
Loop
End With
a = Err.Description
If a = Empty Then DataRefresh = True
Case Else
'Sorry, it's not possible
.Refresh
End Select
End With
endE:
Select Case DataRefresh
Case False
a = Err.Description
BoxText = "data-base refresh failed." & vbCrLf
BoxText = BoxText & "1. Make sure you have grantted access to the SharePoint." & vbCrLf
BoxText = BoxText & "2. Make sure you log in Intranet." & vbCrLf
BoxText = BoxText & "3. Request for support to this Utility Development team." & vbCrLf
u = VBA.MsgBox(BoxText, vbCritical, "DATA-BASE CONNECTION ERROR")
Case True
a = Err.Description
BoxText = "data-base refresh has been successfully completed." & vbCrLf & "You can run the tool..."
u = VBA.MsgBox(BoxText, vbInformation, "DATA-BASE CONNECTION SUCCESSFULL")
End Select |