0

我对 MS Access VBADateValue函数有一个奇怪的问题:当我将值“2012 年 5 月 4 日”传递给它时,它会因类型不匹配错误而失败。

我认为是由于内部日期格式,但我不知道如何在代码级别更改该格式!

目前我的解决方案是:

 Public Function DateToStr(Value)

   Dim Parts As Variant   Parts = Split(Value, " ")
      Dim Month As String
      Select Case Parts(1)
     Case "Jan"
         Month = "Gen"
     Case "May"
         Month = "Mag"
     Case "Jun"
         Month = "Giu"
    Case "Jul"
         Month = "Lug"
     Case "Aug"
         Month = "Ago"
     Case "Sep"
         Month = "Set"
     Case "Oct"
         Month = "Ott"
     Case "Dec"
         Month = "Dic"
     Case Else
         Month = Parts(1)   End Select
      DateToStr = CDate(Parts(0) & "/" & Month & "/" & Parts(2))

 End Function

你有什么主意吗?!?

PS:我的环境是意大利语。

4

1 回答 1

0

在日期值函数中

DateValue ("May 4, 2012")

并制作“2012 年 5 月 4 日”...

Function DateStr(sDS As String) 
'-- format input (sDS) -> dd-mmm-yyyy - ex. "04-Mag-2012" or "04 Mag 2012"

    Dim sMonth As String = ""

    Select Case Mid(sDS, 4, 3)
        Case "Gen" : sMonth = "January"
        ....
        ....
        Case "Dic" : sMonth = "December"
    End Select
    DateStr = sMonth & " " & Left(sDS, 2) & ", " & Right(sDS, 4)

End Function
于 2013-05-20T14:42:05.210 回答