微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MS Access 和系统时间设置关系

如何解决MS Access 和系统时间设置关系

我有 MS Access 数据库查询条件...Documents.DATE>Date()... 它在一台安装了完整 Access (2016) 的计算机上运行良好。 但是在我使用 Access Runtime 版本的其他地方(也是 2016 年),它不起作用。

我已经在完整版的计算机中使用 .accrd-file 尝试过这个查询,它也可以正常工作。什么会导致这种行为?

解决方法

这通常是由于缺少引用引起的。

您将转到菜单工具、参考并检查是否有任何参考被标记为 MISSING 并解决该问题。但是,由于它是一个运行时,您可能需要创建一个小型测试应用程序来列出带有运行时的机器上的引用。这是一个帮助您入门的模块:

Option Compare Database
Option Explicit

' Verify Access' external references.
' Returns True if all references are valid.
' Will run quietly,if called with parameter Quiet as True.
'
' Is intended to be called as the first command from the AutoExec macro
' followed by a call to a function - for example CompileAndSave - that will
' "compile and save all modules".
'
' 2018-07-10. Cactus Data ApS,CPH.
'
Public Function VerifyReferences( _
    Optional ByVal Quiet As Boolean) _
    As Boolean
    
    ' Settings for message box.
    Const Title     As String = "Missing Support Files"
    Const Header    As String = "One or more supporting files are missing:"
    Const Footer    As String = "Report this to IT support." & vbCrLf & "Program execution cannot continue."
    Const Buttons   As Long = VbMsgBoxStyle.vbCritical + VbMsgBoxStyle.vbOKOnly
    
    Dim Reference   As Access.Reference
    
    Dim Item        As Integer
    Dim Guid        As String
    Dim Major       As Long
    Dim Minor       As Long
    Dim Prompt      As String
    Dim Broken      As Boolean
    Dim SecondRun   As Boolean
    Dim Result      As Boolean
    
    Do
        ' Loop (a second time) the references and build a list of those broken.
        Broken = False
        Prompt = ""
        For Each Reference In Access.References
            If Reference.BuiltIn Then
                ' Nothing to check.
            ElseIf IsBrokenExt(Reference) Then
                Broken = True
                Prompt = Prompt & Reference.Guid
                On Error Resume Next
                Prompt = Prompt & " - " & Reference.Name
                On Error GoTo 0
                Prompt = Prompt & vbCrLf
            End If
        Next
        
        If SecondRun Then
            ' Only shuffle the references once.
            Exit Do
        ElseIf Not Broken Then
            ' All references have been verified.
        Else
            ' Try to remove the last non-broken reference and add it back.
            ' This will shuffle the Reference collection and may or may not
            ' cause a broken reference to be added back.
            Item = Access.References.Count
            Do
                Set Reference = Access.References.Item(Item)
                If Not Reference.BuiltIn Then
                    If Not IsBrokenExt(Reference) Then
                        ' Record the reference's identification before removal.
                        Guid = Reference.Guid
                        Major = Reference.Major
                        Minor = Reference.Minor
                        ' Remove this reference.
                        Access.References.Remove Reference
                        ' Add back the removed reference.
                        Access.References.AddFromGuid Guid,Major,Minor
                        Exit Do
                    End If
                End If
                Item = Item - 1
                ' Exit loop when a built-in reference is met.
                ' These are always the top ones.
            Loop Until Reference.BuiltIn
            SecondRun = True
        End If
    Loop Until Not Broken
    
    Result = Not Broken
    
    If Result = False And Quiet = False Then
        Prompt = Header & vbCrLf & vbCrLf & Prompt & vbCrLf & Footer
        VBA.MsgBox Prompt,Buttons,Title
    End If
    
    Set Reference = Nothing
    
    VerifyReferences = Result
    
End Function

' Performs an extended check if a reference is broken,as the
' IsBroken property doesn't check for unregistered files. Thus,' an unregistered reference may fail even if not marked MISSING.
'
' 2018-07-09. Gustav Brock. Cactus Data ApS.
'
Public Function IsBrokenExt( _
    ByRef Reference As Access.Reference) _
    As Boolean

    Dim NotBroken   As Boolean
    
    On Error GoTo Err_IsBrokenExt
    
    ' If the reference is not registered,calling property FullPath will fail.
    ' Even if the file exists in the Virtual File System,GetAttr will find it.
    If (VBA.GetAttr(Reference.FullPath) And vbDirectory) <> vbDirectory Then
        ' FullPath is valid.
        NotBroken = Not Reference.IsBroken
    End If

Exit_IsBrokenExt:
    IsBrokenExt = Not NotBroken
    Exit Function
    
Err_IsBrokenExt:
    ' Ignore non-existing servers,drives,and paths.
    Resume Exit_IsBrokenExt
  
End Function

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。