vba - 在计算字段中查找最小数字
问题描述
在 MSAccess 报告中,我有以下字段:CurrentHours、Insp1DueTime、Insp2DueTime...Inspn3DueTime 等。我想要一个计算字段,输出 (Insp1DueTime-CurrentHours)、(Insp2DueTime-Currenthours)、(Insp3DueTime-CurrentHours) 的最小值, ETC。
是否有一个 VBA 命令可以执行此操作,类似于' minimumvalue '((currenthours-insp1duetime), (Currenthours-insp2duetime),...(currenthour-InspnDueTime))
解决方案
Nope, but you can make one really easily, using a ParamArray
:
Public Function SmallestValue(ParamArray Values())
Dim Value
For Each Value In Values
If IsEmpty(SmallestValue) Or SmallestValue > Value Then
SmallestValue = Value
End If
Next
End Function
A paramarray takes any input, and puts it into an array. You iterate over that array, and test if things are larger or smaller.
This works with any input, e.g.: SmallestValue(2,1,3,4)
returns 1
, SmallestValue(Now(), Date(), #1/1/2001#)
returns #1/1/2001#
, SmallestValue("banana", "apple", "pear")
returns "apple"
推荐阅读
- uwp - RichEditBox looses color formatting when disable then enable
- mongodb - Mongoose 5.3.1 ofFail() 助手问题
- javascript - 试图通过拼接和传播将一个数组插入另一个数组,返回空
- javascript - dest.on 不是 gulp 任务中的函数
- android - 使用改造从 json 字符串中解析动态键
- javascript - 更新网页上的数据(带有厚重的 leaflet.js 图表)
- python-3.x - Difference in the receive and send method in a websocket
- pdf - JavaFX - 以编程方式设置目标路径以直接将节点打印到 pdf 文件
- java - 从 jar 文件中的方法调用外部类
- r - 使用 ggplot2 在直方图中显示百分比而不是计数 R