2017-10-18 2 views
0

J'ai emprunté ce code et cela semble fonctionner correctement. Cependant, je voudrais qu'il affiche un message si le proc stocké ne renvoie aucun enregistrement? Votre aide est grandement appréciée.Code VBA appelant une boîte de message proc-display stockée si aucun enregistrement n'est retourné

Private Sub CommandButton1_Click() 

Dim property_id As Double 

property_id = Sheets("Pro Forma Input").Range("AD3").Value 

With ActiveWorkbook.Connections("MyDataConnection").OLEDBConnection 
.CommandText = "EXEC dbo.my_stored_proc '" & property_id & "'" 
ActiveWorkbook.Connections("MyDataConnection").Refresh 

End With 
Application.DisplayAlerts = True 

End Sub 
+0

Cette connexion est attachée à quelque chose (une table de requête, un objet de liste, une table pivotante). Vérifiez les données qu'ils ont après l'actualisation. – GSerg

Répondre

0

Essayez ceci:

property_id = Sheets("Pro Forma Input").Range("AD3").Value 

If property_id = "" Then 
    MsgBox "There is nothing here!" 
Else 
End If 

Hope this helps!

+1

Je pense qu'il veut dire que si la procédure stockée SQL ne renvoie aucune ligne – KacireeSoftware

0

Merci pour l'autre affiche pour la solution, pour une raison quelconque son message a été supprimé. Voici ce que j'ai fait au cas où quelqu'un d'autre en aurait besoin.

With ActiveWorkbook.Connections("FirstKey_One_Pager_connection").OLEDBConnection 
.CommandText = "EXEC dbo.usp_FirstKey_One_Pager '" & property_id & "'" 
ActiveWorkbook.Connections("FirstKey_One_Pager_connection").Refresh 

If Sheets("DataSource").Range("B9").Value = "" Then 
    MsgBox "No property found using the RR ID entered" 
Else 
End If