2015-01-07 2 views
0

이 방법을 사용하여 Access 2010/13에 밀리 초 타임 스탬프를 구현하려고합니다. MS Access Can Handle Millisecond Time Values--Really - See more at:밀리 초 시간 : 날짜별로 필터 양식

밀리 초 값은 다음과 같이 쿼리됩니다. SELECT DateValueMsec([DateTimeMs]) AS DateOnly FROM - 텍스트 상자에서 양식을 정렬하기위한 날짜 전용 제어를 제공합니다. DateOnly yeilds 0에서 결과에 프로그래밍 방식으로 필터가 적용되었습니다.

Private Sub BuildFilter() 
    Dim strFilter As String 
    Dim ctl As Control 

    strFilter = "" 

'add selected values to string 
    For Each ctl In Me.FormHeader.Controls 
     With ctl 
      If .ControlType = acTextBox Or .ControlType = acComboBox Then 
       If Nz(.Value) <> "" Then 
        If InStr(.Name, "Date") <> 0 Then 
         If Nz(StartDate) <> "" And Nz(EndDate) <> "" And InStr(strFilter, "DateOnly") = 0 Then 
          strFilter = strFilter & "[DateOnly] BETWEEN #" & Me.StartDate.Value & "# AND #" & Me.EndDate.Value & "# AND " 
         ElseIf Nz(StartDate) <> "" And InStr(strFilter, "DateOnly") = 0 Then 
         strFilter = strFilter & "[DateOnly] >= #" & DateValueMsec(Me.StartDate.Value) & "# AND " 
        '  strFilter = strFilter & "[DateOnly] >= #" & Me.StartDate.Value & "# AND " 
         ElseIf Nz(EndDate) <> "" And InStr(strFilter, "DateOnly") = 0 Then 
          strFilter = strFilter & "[DateOnly] <= #" & Me.EndDate.Value & "# AND " 
         End If 
        ElseIf InStr(.Name, "ID") <> 0 Then 
         strFilter = strFilter & "[" & .Name & "] = " & .Value & " AND " 
        Else 
         strFilter = strFilter & "[" & .Name & "] = '" & .Value & "' AND " 
        End If 
       End If 
      End If 
     End With 
    Next ctl 
'trim trailing 
    strFilter = TrimR(strFilter, 5) 

Debug.Print strFilter 
    With Me.subfrmzzAuditTrailDisplay 
     .Form.Filter = strFilter 
     .Form.FilterOn = True 
    End With 
End Sub 
+0

다른 데이터 유형을 시도했습니다. 쿼리 된 값 및 필터가 ** 날짜 ** 인 경우; 결과는 0 입니다. ** 문자열 ** 결과가 모두 인 경우 필터가 적용될 때 –

답변

0

답변! @pathDongle에서

시간은 밀리 초 UTC로 저장됩니다.

!DateTimeMS = GetTimeUTC() 

Public Function UTCtoTimeLocal(dSysUTC As Date) As Date 
'Dim sysTime As SYSTEMTIME 
    Dim DST As Long 
    Dim tzi As TIME_ZONE_INFORMATION 

    DST = GetTimeZoneInformation(tzi) 
    UTCtoTimeLocal = dSysUTC - TimeSerial(0, tzi.Bias, 0) + IIf(DST = 2, TimeSerial(1, 0, 0), 0) 
End Function 

쿼리;

SELECT tblzzAuditTrail.DateTimeMS, FormatDate(UTCtoTimeLocal([DateTimeMS])) AS DateTimeLocal 

문자열로 필터링 할 수 있습니다.

Private Sub BuildFilter() 
    Dim strFilter As String 
    Dim ctl As Control 

    strFilter = "" 

'add selected values to string 
    For Each ctl In Me.FormHeader.Controls 
     With ctl 
      If .ControlType = acTextBox Or .ControlType = acComboBox Then 
       If Nz(.Value) <> "" Then 
        If InStr(.Name, "Date") <> 0 Then 
         If Nz(StartDate) <> "" And Nz(EndDate) <> "" And InStr(strFilter, "DateTimeLocal") = 0 Then 
          strFilter = strFilter & "[DateTimeLocal] BETWEEN '" & FormatDate(Me.StartDate.Value) & "' AND '" & FormatDate(Me.EndDate.Value) & "' AND " 
         ElseIf Nz(StartDate) <> "" And InStr(strFilter, "DateTimeLocal") = 0 Then 
          strFilter = strFilter & "[DateTimeLocal] > '" & FormatDate(Me.StartDate.Value) & "' AND " 
         ElseIf Nz(EndDate) <> "" And InStr(strFilter, "DateTimeLocal") = 0 Then 
          strFilter = strFilter & "[DateTimeLocal] <= '" & FormatDate(Me.EndDate.Value) & "' AND " 
         End If 
        ElseIf InStr(.Name, "ID") <> 0 Then 
         strFilter = strFilter & "[" & .Name & "] = " & .Value & " AND " 
        Else 
         strFilter = strFilter & "[" & .Name & "] = '" & .Value & "' AND " 
        End If 
       End If 
      End If 
     End With 
    Next ctl 
'trim trailing And 
    strFilter = TrimR(strFilter, 5) 

Debug.Print strFilter 
    With Me.subfrmzzAuditTrailDisplay 
     .Form.Filter = strFilter 
     .Form.FilterOn = True 
    End With 
End Sub 

결과 필터 문자열;

[UserID] = 2 AND [DateTimeLocal] BETWEEN '06/01/2015 00:00:00.000' AND '07/01/2015 00:00:00.000' 

다른 나의 질문에 따르면;

millisecond-time-msec2-incorrect-return