VBA 搜索外部数据 table 的记录

VBA to search the external data table for a record

我link在 Visio 2013 中编辑了外部数据,并且有四种不同的 tabs/tables。当用户双击形状时,该形状的文本将用于搜索 table 中的记录。请注意,此数据未在 Visio linked 数据方法中 linked。只需要手动搜索table,而不是依赖于数据记录和预先存在的形状之间的一些link。 外部数据导入正常。我可以捕获双击形状的文本。如果您能告诉我如何 运行 针对已提取到 Visio 中的外部数据进行查询,然后突出显示该行。 谢谢

获得有关数据源的信息(例如 server/database 名称、凭据等)后,您只需要在模块中添加几行 VBA,如下所示:

Dim theVariableForDataFieldYouWant as Integer
Dim db as database
Dim rs as recordset
Set db = YourDataConnectionStringHere
Dim sql as string
sql = "Select aFieldYouWant, anotherFieldYouWant from yourTableName WHERE someField = yourCriteria"
set rs = db.openRecordSet(sql)

if rs.eof then
' you recordset is empty, nothing matched
else
theVariableForDataFieldYouWant = rs.fields("theDataField")
end if

rs.close
db.close
set rs = nothing
set db = nothing

如果您提供更多细节,我可以更准确,但基本上就是这样。将代码放入函数或子函数中,然后在您选择的事件上调用它。