vba - 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
我知道此代码在帖子中看起来不正确,但由于这是我第一次在这里发帖,如果有人能指出我的错误,我将不胜感激。另外,我在网站上搜索了这个问题的答案,但没有找到与这个特定示例相关的答案。
解决方案
这是你想要的吗 ?
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
推荐阅读
- python - 用一行中的项目数转换新列
- sql - 使用左连接和不同的总和不正确的值
- hazelcast - hazelcast 主题作为 hazelcast-jet 源
- mysql - 页面重定向问题 Node-js
- python - 在 Python 中将输入格式化为十进制价格
- c++ - 为什么阻止将反向迭代器 .rbegin() 用作要擦除的元素的位置?
- java - Spring 引导数据休息 - @RestResource(exported = false) 不适用于继承的方法。(保存,删除)
- python - 使用 BeautifulSoup 检查动态生成的页面上是否存在字符串
- angular - 我如何知道数据何时加载到 p-tree 上并选择第一个节点?
- javascript - vue js中的状态管理具有多个if条件以使用ID获取数据