简体   繁体   English

要访问的 VBA Excel 代码

[英]VBA Excel code to Access

I have a code below that I created for Excel.我在下面有一个为 Excel 创建的代码。 I am now trying to apply it to Access.我现在正在尝试将其应用于 Access。 There are changes that were made to the code that should have made it compatible for Access but it's still giving me an error.对代码进行了一些更改,应该使其与 Access 兼容,但它仍然给我一个错误。 I'm not understanding what this error is and what to do about it:我不明白这个错误是什么以及如何处理它:

Option Compare Database
Public Function OldMaturity(term As String, invoicedate As Date, days As Long) As Date

Dim d As Date
Select Case term.Value
    Case "STD":
        OldMaturity = DateAdd("y", days.Value, invoicedate.Value)

    Case "BONM":
        d = DateAdd("y", days.Value, invoicedate.Value)
        OldMaturity = DateAdd("m", 1, DateSerial(Year(d), Month(d), 1))

    Case "EOM":
        d = DateAdd("y", days.Value, invoicedate.Value)
        OldMaturity = DateAdd("y", -1, DateAdd("m", 1, DateSerial(Year(d), Month(d), 1)))

    Case Else:
        OldMaturity = CDate("99/99/9999")
End Select
End Function

Public Function NewMaturity(invoicedate As Date) As Date
Dim val1 As Long
Dim val2 As Long

val1 = invoicedate + 120
val2 = DateAdd("m", 1, val1)
NewMaturity = DateSerial(Year(val2), Month(val2), 1)

End Function

This is the error that's showing:这是显示的错误:

在此处输入图片说明

An alternative version of your NewMaturity function:您的NewMaturity函数的替代版本:

Public Function NewMaturity(ByVal invoicedate As Date) As Date
    Dim d As Date
        d = DateAdd("m", 1, DateAdd("y", 120, invoicedate))

    NewMaturity = DateSerial(Year(d), Month(d), 1)
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM