我借用了这段代码,似乎工作正常。但是,如果存储的proc没有返回记录,我希望它显示一条消息?非常感谢您的帮助。
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 :(得分:0)
试试这个:
property_id = Sheets("Pro Forma Input").Range("AD3").Value
If property_id = "" Then
MsgBox "There is nothing here!"
Else
End If
希望这有帮助!
答案 1 :(得分:0)
感谢解决方案的另一张海报,由于某种原因,他/她的帖子被删除了。这是我做过的事,以防其他人需要它。
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