プロが教える店舗&オフィスのセキュリティ対策術

日付を比較してstrToDateよりstrFromDateの日付が未来日だった場合エラーを出したいのですがうまくいきません。
日付型に合わせたつもりなのですがこれだとダメなのでしょうか


strFromTime = txtFromYear & "/" & Format(txtFromMonth, "00") & "/" & Format(txtFromDay, "00")
strToTime = txtToYear & "/" & Format(txtToMonth, "00") & "/" & Format(txtToDay, "00")

If (Format(strFromTime, yyyy / mm / dd) >
  Format(strToTime, yyyy / mm / dd)) Then
MsgBox MSG_ERR, vbCritical, SYSTEM_NAME
Exit Sub
End If

A 回答 (2件)

シリアル値で比較してもエラーがあがりますか?

    • good
    • 0

Format関数の使い方が間違っています



>(Format(strFromTime, yyyy / mm / dd)
テキスト型の第1項目に対しy,m,dは使えません。構文も間違っています

文字列を比較したいのであれば単純に
If strFromTime > strToTime Then
でいいのでは

日付時刻型で比較するのなら

If DAteValue(strFromTime) > DateValue(strToTime) Then
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!