首页 > 解决方案 > MS-Access 按钮正在使用 fileModDate = f.DateLastModified;我如何将 fileModDate 与今天的日期进行比较

问题描述

在这个数据库中,一周中的每一天都有按钮;用户需要单击与星期几相关的按钮,这将执行一些基本功能。我需要添加一个意外事件,使代码查看按钮将查看的文件的最后修改日期并将其与今天的日期进行比较。如果最后修改的日期不是今天的日期,那么我不希望用户能够执行该按钮后面的命令,并被迫执行正确的按钮,这实际上与一周中的当前日期有关。

Private Sub Command19_Click()

    Dim FSO As Object

    Dim FromPath As String
    Dim ToPath As String
    Dim FileExt As String

    Dim fileModDate As String

    Dim Response2 As Integer

    'To have a second message box, do I need to set another parameter here? I.E Dim Response3 As Integer (?)

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile("\\file_path\file_name.csv")

    fileModDate = f.DateLastModified

    Response2 = MsgBox(prompt:="Files are dated - " & fileModDate & ". Do you wish to Continue?", Buttons:=vbYesNo)

    If Response2 = vbNo Then

        Exit Sub

    Else

        'I assume I need to compare fileModDate to current date here. IF this is today's date then continue, IF NOT, then prompt user with message, "Button date does not match today's date". Do not allow user to continue until they have clicked a button for which the fileModDate = today's date.

    End If

    FromPath = "\\file_path"
    ToPath = "\\file_path"

    MsgBox "Files Copied"

End Sub

我知道此代码在帖子中看起来不正确,但由于这是我第一次在这里发帖,如果有人能指出我的错误,我将不胜感激。另外,我在网站上搜索了这个问题的答案,但没有找到与这个特定示例相关的答案。

标签: vbams-access

解决方案


这是你想要的吗 ?

    If Format(F.DateLastModified, "dd/mm/yyyy") <> Format(Now, "dd/mm/yyyy") Then
        MsgBox ("Button date does not match today's date")
        Exit Sub
    End If

推荐阅读