Microsoft Access 掲示板

締日・支払期日をユーザー定義関数で作りたい / 3

11 コメント
views
4 フォロー
3
hatena 2025/02/19 (水) 09:41:11 修正 >> 2

VBAは、Is Null は使えないので、代わりにIsNull関数を使います。

Function 締め日付(締め実日, 売上日付)
    締め日付 = IIf(IsNull(締め実日), 売上日付, DateSerial(Year(売上日付), Month(売上日付) + IIf(Day(売上日付) > 締め実日, 1, 0), 締め実日))
End Function

あと、VBAを使うならIf構文を使った方が読みやすいように思います。

Function 締め日付(締め実日, 売上日付)
    If IsNull(締め実日) Then
        締め日付 = 売上日付
    Else
        締め日付 = DateSerial(Year(売上日付), Month(売上日付), 締め実日)
        If Day(売上日付) > 締め実日 Then 締め日付 = DateAdd("m", 1, 締め日付)
    End If
End Function
通報 ...