此函数MRound在MS Access中不存在,您不能只安装它。
我正尝试在Access报告中使用mround函数。该函数未在内置函数的表达式生成器框中列出。当我使用计算,例如,=mround([AmountDue],0.05),并运行报告时,它要求提供参数mround。
发布于 2019-11-04 06:25:12
您可以在公共VBA模块中定义自己的模块,例如:
Function MRound(dblNum As Double, dblMtp As Double) As Double
MRound = dblMtp * Round(dblNum / dblMtp, 0)
End Function或者,将对Microsoft Excel对象库的引用添加到VBA工程中(工具>引用),并将公共VBA模块中的MRound函数定义为:
Function MRound(dblNum As Double, dblMtp As Double) As Double
MRound = Excel.WorksheetFunction.MRound(dblNum, dblMtp)
End Function发布于 2019-11-04 18:58:49
Access中没有MRound,因此请创建您自己的舍入函数。
但是,千万不要使用Round,因为它有臭名昭著的buggy。因此,请使用普通数学和数据类型Decimal来避免错误:
' Rounds a value by 4/5 to the nearest multiplum of a rounding value.
' Accepts any value within the range of data type Currency.
' Mimics Excel function MRound without the limitations of this.
'
' Examples:
'
' RoundAmount(-922337203685477.5808, 0.05) -> -922337203685477.6
' RoundAmount( 922337203685477.5807, 0.05) -> 922337203685477.6
' RoundAmount( 10, 3) -> 9
' RoundAmount(-10,-3) -> -9
' RoundAmount( 1.3, 0.2) -> 1.4
' RoundAmount( 122.25, 0.5) -> 122.5
' RoundAmount( 6.05, 0.1) -> 6.1
' RoundAmount( 7.05, 0.1) -> 7.1
' 2009-05-17. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function RoundAmount( _
ByVal Value As Currency, _
ByVal RoundValue As Currency) _
As Variant
Dim BaseValue As Variant
Dim Result As Variant
BaseValue = Int(Value / CDec(RoundValue) + CDec(0.5))
Result = BaseValue * RoundValue
RoundAmount = Result
End Function例如,此函数将正确地舍入以下内容:
Amount = RoundAmount( 122.25, 0.5)
Amount -> 122.50有关精确舍入的详细信息,请参阅我在GitHub上的项目
以及本文所指的文章。
https://stackoverflow.com/questions/58684800
复制相似问题